replace   characters that are hidden in text

This solution will work, I tested it:

$string = htmlentities($content, null, 'utf-8');
$content = str_replace(" ", "", $string);
$content = html_entity_decode($content);

Not tested, but if you use something like:

$string = preg_replace("/\s/",'',$string);

That should remove all spaces.

UPDATE

To remove all spaces and   references, use something like:

$string = preg_replace("/\s| /",'',$string);

UPDATE 2

Try this:

$string = html_entity_decode($string);

$string = preg_replace("/\s/",'',$string);

echo $string;

Forgot to say, reconvert the html entities so add this after the replacement:

htmlentities($string);

All solutions above kind of work, until one starts to work with German language where there are such letters:

ä ä

and othere simial ones. I use the following code:

$string = preg_replace ( "!\s++!u", ' ', $string );

More details here: PCRE(3) Library Functions Manual

Tags:

Php

Unicode

Regex