Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert/replace U+2009 character with space

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried this:

$str = utf8_decode($str);

But it converts that character to question mark ?

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading