note 103443 deleted from reference.pcre.pattern.modifiers by danbrown

From: Date: Wed, 13 Apr 2011 18:37:17 +0000
Subject: note 103443 deleted from reference.pcre.pattern.modifiers by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178808@lists.php.net to get a copy of this message
Note Submitter: phofstetter at sensational dot ch ---- 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!

« previous php.notes (#178808) next »