note 103443 added to reference.pcre.pattern.modifiers
| From: | phofstetter at sensational dot ch | Date: | Wed, 13 Apr 2011 18:34:30 +0000 |
| Subject: | note 103443 added to reference.pcre.pattern.modifiers | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178806@lists.php.net to get a copy of this message | ||
Yes. That note about needing to use the u modifier only if you want utf-8 in your pattern is not
correct.
Especially together with preg_replace, it becomes imperative that you use the u modifier if your
subject contains UTF-8 encoded data, otherwise depending on regular expression, you will get
corrupted data from the replacement operation.
I just spend a few painful minutes with this
<?php
$in = 'éà ';
$out = preg_replace('#\s+#', ' ', $in);
echo "$in\n$out\n";
?>
which was echoing the original é plus a corrupted high-bit value plus a space character
Reason?
à is encoded as 0xc3a0 and 0xa0 is seen as whitespace matching \s if you don't provide the
u-flag.
Be really, really careful about this!
----
Server IP: 194.153.94.10
Probable Submitter: 77.56.160.123
----
Manual Page -- http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
Edit -- https://master.php.net/note/edit/103443
Del: integrated -- https://master.php.net/note/delete/103443/integrated
Del: useless -- https://master.php.net/note/delete/103443/useless
Del: bad code -- https://master.php.net/note/delete/103443/bad+code
Del: spam -- https://master.php.net/note/delete/103443/spam
Del: non-english -- https://master.php.net/note/delete/103443/non-english
Del: in docs -- https://master.php.net/note/delete/103443/in+docs
Del: other reasons-- https://master.php.net/note/delete/103443
Reject -- https://master.php.net/note/reject/103443
Search -- https://master.php.net/manage/user-notes.php