<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[preg_replace比ereg_replace快多少？]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Wed, 11 Oct 2006 23:51:50 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	preg_replace是Perl内置的一种文字匹配模式，不过用起来一些参数会比ereg_relace复杂一些，实际的项目运用中，用ereg的人还是不少，近日我写了一个获取HTML中的文本的函数，发现preg_replace居然比ereg_replace快了近一倍，两个函数如下： <br/><br/>用preg_replace <br/><br/>function GetHtmlText($str)<br/>{<br/> $str = preg_replace(&quot;/&lt;sty(.*)&#92;/style&gt;&#124;&lt;scr(.*)&#92;/script&gt;&#124;&lt;!--(.*)--&gt;/isU&quot;,&quot;&quot;,$str);<br/> &nbsp;$alltext = &quot;&quot;;<br/> &nbsp;$start = 1;<br/> &nbsp;for($i=0;$i&lt;strlen($str);$i++){<br/> &nbsp; &nbsp;if($start==0 &amp;&amp; $str[$i]==&quot;&gt;&quot;) $start = 1;<br/> &nbsp; &nbsp;else if($start==1){<br/> &nbsp; &nbsp; if($str[$i]==&quot;&lt;&quot;){ $start = 0; $alltext .= &quot; &quot;; }<br/> &nbsp; &nbsp; else if(ord($str[$i])&gt;32) $alltext .= $str[$i];<br/> &nbsp; &nbsp;}<br/> &nbsp;}<br/> &nbsp;$alltext = preg_replace(&quot;/&amp;([^;&amp;]*)(;&#124;&amp;)/&quot;,&quot; &quot;,$alltext);<br/> &nbsp;$alltext = preg_replace(&quot;/　{1,}/&quot;,&quot; &quot;,$alltext);<br/> &nbsp;$alltext = preg_replace(&quot;/ {1,}/&quot;,&quot; &quot;,$alltext);<br/> &nbsp;return $alltext;<br/>} <br/><br/>用ereg_replace <br/><br/>function GetHtmlText($str)<br/>{<br/> $str = eregi_replace(&quot;&lt;sty(.*)/style&gt;&#124;&lt;scr(.*)/script&gt;&#124;&lt;!--(.*)--&gt;&quot;,&quot;&quot;,$str);<br/> &nbsp;$alltext = &quot;&quot;;<br/> &nbsp;$start = 1;<br/> &nbsp;for($i=0;$i&lt;strlen($str);$i++){<br/> &nbsp; &nbsp;if($start==0 &amp;&amp; $str[$i]==&quot;&gt;&quot;) $start = 1;<br/> &nbsp; &nbsp;else if($start==1){<br/> &nbsp; &nbsp; if($str[$i]==&quot;&lt;&quot;){ $start = 0; $alltext .= &quot; &quot;; }<br/> &nbsp; &nbsp; else if(ord($str[$i])&gt;32) $alltext .= $str[$i];<br/> &nbsp; &nbsp;}<br/> &nbsp;}<br/> &nbsp;$alltext = ereg_replace(&quot;&amp;([^;&amp;]*)(;&#124;&amp;)&quot;,&quot; &quot;,$alltext);<br/> &nbsp;$alltext = ereg_replace(&quot;　{1,}&quot;,&quot; &quot;,$alltext);<br/> &nbsp;$alltext = ereg_replace(&quot; {1,}&quot;,&quot; &quot;,$alltext);<br/> &nbsp;return $alltext;<br/>} <br/><br/>经过多次测试对比，用preg_replace的函数普遍在 0.08-0.12秒之间，用ereg_replace的函数却去到0.35-0.38秒之间，测试的网页为百度的主页，我的系统是图拉丁 1.1G的CPU，384M的内存。 <br/><br/>如果你的程序中还有使用ereg处理较长文本的，建议马上更改过来。 <br/><br/><br/><br/><br/>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] preg_replace比ereg_replace快多少？]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>