phant0m Posted July 22, 2009 Share Posted July 22, 2009 I have reinstalled my computer and therefore a newer version of XAMPP. This now leads to strange results with preg_match. Consider the following code: <?php $string = 'asdfsadfasdf asdfa adsf dsa fdsa fdsa dsa fdsa fdsaf dsa dsa fdsa fdsaf sad fdsf sad dsfgdsfg asdfsadfadfsadfasdadffa aa fddsaf sad fdsf sadfasdf asaaaaadfa adsf dsa fdsa fdsa dsa fdsaa dsa faaaaaaaadaaaaaaaaaaaasaf dsa faaaaadaaaaaaaaaasaf dsa dsa fdsa fdsaf sad fdsf sad daaaaasfgdsfg asdfsadfaaaasdf asdfa adsf dsa fdsa fdsa dsa fdsa fdsaf dsa dsa fdsa fdsaf sad fdasf asad dsfgdsfg aaaaaa'; $pattern= preg_match('%^(?: [\x09\x0A\x0D\x20-\x7E] # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$%xs'; preg_match($pattern, $string); ?> This code works. However, if I was to insert one single character more in $string, PHP crashes without telling me why. [Wed Jul 22 21:51:08 2009] [notice] Parent: child process exited with status 3221225477 -- Restarting. The string is very often much longer than that, and online it works flawlessly. This is online: PHP Version 5.2.6 PCRE Library Version 6.6 06-Feb-2006 pcre.backtrack_limit 100000 pcre.recursion_limit 100000 This is offline: PHP Version 5.2.9 PCRE Library Version 7.8 2008-09-05 pcre.backtrack_limit 100000 pcre.recursion_limit 100000 any ideas? Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/ Share on other sites More sharing options...
phant0m Posted July 23, 2009 Author Share Posted July 23, 2009 no one? Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-881085 Share on other sites More sharing options...
Mark Baker Posted July 23, 2009 Share Posted July 23, 2009 I encountered a similar problem, trying to validate utf-8: on some servers the preg_match ran without problems, on others it simply crashed without error. Suspected that it was related to the regexp library versions, but resolved it by using $charset = (mb_check_encoding($string,'ISO-8859-1')) ? 'ISO-8859-1' : 'UTF-8'; instead Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-881096 Share on other sites More sharing options...
thebadbad Posted July 23, 2009 Share Posted July 23, 2009 I'm guessing the forum messed with your code? 'Cause it would throw a syntax error the way it is there. Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-881102 Share on other sites More sharing options...
phant0m Posted July 23, 2009 Author Share Posted July 23, 2009 ah yes, you need to remove preg_match( from $pattern = - sorry for that (why can't I edit my post?) @Mark: thanks, I'll try that. Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-881108 Share on other sites More sharing options...
phant0m Posted July 24, 2009 Author Share Posted July 24, 2009 Thanks, it worked! Let's just hope I don't run into other problems with regex. Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-881793 Share on other sites More sharing options...
saratis Posted August 3, 2009 Share Posted August 3, 2009 Could go into a little more detail as to how you implemented this? Im having the same problem. Thank you Link to comment https://forums.phpfreaks.com/topic/167022-solved-preg_match-crashes-php/#findComment-889729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.