php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53956 Zero Width Space is not replaced by ordinary space
Submitted: 2011-02-08 10:45 UTC Modified: 2011-02-08 22:12 UTC
From: skyboy at mail dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.5 OS: Ubuntu 10.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 + 22 = ?
Subscribe to this entry?

 
 [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) "​​‎​​‎​​‎" 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-08 11:15 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-02-08 11:15 UTC] aharvey@php.net
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.
 [2011-02-08 21:40 UTC] skyboy at mail dot ru
oh!sorry for this. this is my mistake.
but why "zero width *space*" does not belong to [s]pace symbols' group?
 [2011-02-08 22:12 UTC] rasmus@php.net
You should ask the PCRE guys about that.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 17:05:44 2022 UTC