Convert/replace U+2009 character with space

Jay.

I have a string that contains unreadable space character:

enter image description here

How can I replace this character with a normal space so I can get a string like: "a b c d"

I have tried this:

$str = utf8_decode($str);

But it converts that character to question mark ?

Manik

Try to replace using preg match -

$string = "   test   string and XY \t ";

$trimString = trim(preg_replace('/[\pZ\pC]/u', ' ', $string));
//test\x20\x20\x20string\x20and\x20XY

Details

  • ^[\pZ\pC]+ - one or more whitespace or control chars at the start of string

  • | - or [\pZ\pC]+$ - one or more whitespace or control chars at the end of string

  • | - or (?! )[\pZ\pC] - one or more whitespace or control chars other than a regular space anywhere inside the string

  • [^\S ] - any whitespace other than a regular space (\x20)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related