note 117314 added to function.preg-replace
| From: | (at) | Date: | Wed, 20 May 2015 09:22:47 +0000 |
| Subject: | note 117314 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202618@lists.php.net to get a copy of this message | ||
Warning, preg_replace() has an unexpected behaviour on UTF-8 strings when you use an empty regular
expression like "/()/" !
If you build your regular expression in PHP like this :
$words = array();
foreach (explode(" ", $what) as $w)
if (mb_strlen($w) > 0)
$words[] = preg_quote($w, "/");
return preg_replace('/(' . implode("|",$words) . ')/iu',
'<span class="text-maroon">\\1</span>', $text);
Always check if $words array isn't empty :
if (count($words) == 0)
return $text;
----
Server IP: 72.52.91.14
Probable Submitter: 80.13.205.55
----
Manual Page -- http://php.net/manual/en/function.preg-replace.php
Edit -- https://master.php.net/note/edit/117314
Del: integrated -- https://master.php.net/note/delete/117314/integrated
Del: useless -- https://master.php.net/note/delete/117314/useless
Del: bad code -- https://master.php.net/note/delete/117314/bad+code
Del: spam -- https://master.php.net/note/delete/117314/spam
Del: non-english -- https://master.php.net/note/delete/117314/non-english
Del: in docs -- https://master.php.net/note/delete/117314/in+docs
Del: other reasons-- https://master.php.net/note/delete/117314
Reject -- https://master.php.net/note/reject/117314
Search -- https://master.php.net/manage/user-notes.php