|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-02-08 10:45 UTC] skyboy at mail dot ru
Description:
------------
Group of zero width spaces is succesfully replaced by any character but ordinary space.
Test script:
---------------
$str = ""; // 27 zero width spaces with unicode code of u200B
var_dump($str);
var_dump(preg_replace('#\s+#', $str, '-'));
var_dump(preg_replace('#\s+#', $str, ' '));
Expected result:
----------------
string(27) "" string(1) "-" string(1) "-"
Actual result:
--------------
string(27) "" string(1) "-" string(27) ""
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 21:00:02 2025 UTC |
Your arguments to preg_replace are swapped, ie: preg_replace('#\s+#', $str, '-'); should be: preg_replace('#\s+#', '-', $str); Also note that Unicode zero width spaces aren't included in \s, but you can match them directly with the u modifier (replace <200b> with an actual zero width space character): preg_replace('#<200b>+#u', '-', $str); Not a bug: closing.