On Wed, Nov 19, 2003 at 04:54:39PM -0500, Scott Fletcher wrote: : : "Ray" <[EMAIL PROTECTED]> wrote: : > try : > $res_str_len = strlen($res_str); : > for ($i=1;$i<$res_str_len;++$i) : > : > one less function call in the loop and the prefix version of ++ is : > sometimes a tad faster then the postfix version. : : That's a great idea! Recently changed the code and the postfix of ++ to : prefix of ++. Still about the same... : : What so odd about this script is that I wrote it in Visual Basic for one of : the application. It took only a few seconds for a PC workstation (Pentium : 3 - Windows 2000). So, converting this code to PHP and place it on the Unix : Server (RS/6000) Webserver and it take way too long....
I tried it myself. The old code that calculated strlen() on each iteration took around 8.2 seconds. The new code that ran strlen() once and stored the results in a variable took around 5.6 seconds. However, the big problem with your code is that you manually iterate through every character of the string, then do your search for both "<![CDATA[" and "]]>". That's not an efficient search algorithm at all. Take a look at strpos() to get at least 1-2 orders of magnitude of speedup. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php