note 97813 deleted from function.preg-replace by danbrown

From: Date: Mon, 10 May 2010 12:12:52 +0000
Subject: note 97813 deleted from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169118@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- preg_replace (and str_replace too) will crash php if you use ' ' (space) as replace value for a large number of matches. For example: $string = preg_replace('/( )+/', ' ', $string); $string = str_replace(' ', ' ', $string); will crash if $string contains many seperate matches of ' ' producing following Apache Error-Log message: [Mon May 10 09:23:58 2010] [notice] child pid 39251 exit signal Illegal instruction (4) where pid 39251 was the PHP-thread processing that request. $string = preg_replace('/( )+/', '', $string); $string = str_replace(' ', '', $string); or $string = preg_replace('/( )+/', '_', $string); $string = str_replace(' ', '_', $string); do all work fine. This seems to be a bug in the underlying PCRE implementation, and not in PHP itself.

« previous php.notes (#169118) next »