note 97813 added to function.preg-replace
| From: | Anonymous at osu1 dot php dot net | Date: | Mon, 10 May 2010 08:44:14 +0000 |
| Subject: | note 97813 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169106@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 85.214.154.209
Probable Submitter: 213.47.87.9
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/97813
Del: integrated -- https://master.php.net/note/delete/97813/integrated
Del: useless -- https://master.php.net/note/delete/97813/useless
Del: bad code -- https://master.php.net/note/delete/97813/bad+code
Del: spam -- https://master.php.net/note/delete/97813/spam
Del: non-english -- https://master.php.net/note/delete/97813/non-english
Del: in docs -- https://master.php.net/note/delete/97813/in+docs
Del: other reasons-- https://master.php.net/note/delete/97813
Reject -- https://master.php.net/note/reject/97813
Search -- https://master.php.net/manage/user-notes.php