String matching for sample code doesn't work....

From: Date: Wed, 19 Nov 2003 17:47:41 +0000
Subject: String matching for sample code doesn't work....
Groups: php.general 
Request: Send a blank email to php-general+get-170327@lists.php.net to get a copy of this message
Hi Everyone! I'm not really sure why does this simple script not work. When I run the code, the loop kept going until it timed out. I'll enclose the simple code here... --snip-- $res_str = "<Dog Name>Whoof</Dog Name><![CDATA[Whose Dog is that??]]>"; for ($i=0;$i<1000000;$i++) { if (substr($res_str, $i, 9) == "<![CDATA[") { echo "You got it!!!!"; } } --snip-- This one should work but it doesn't, but I noticed that it does work if I use this instead... --snip-- if (substr($res_str, $i, 7) == "[CDATA[") --snip-- So, the problem had to do with either the '<' character or the '!' character that doesn't match. I thought maybe an escape character would work, like '\' but it doesn't do anything. So, anyone know how to fix that problem? Thanks, Scott F.

« previous php.general (#170327) next »