replace   characters that are hidden in text

How to remove   (that are hidden) and SPACES in below text but

  • hold UNICODE characters
  • hold <br> tag

i tested:

  • i used trim($string) => NOT WORKED
  • i used str_replace('&nbsp;', '', $string) => NOT WORKED
  • i used some regex => NOT WORKED

                <br>تاريخ ورود: یکشنبه ۲۳ بهمن ماه ۱۳۹۰
    

UPDATE: Image of hidden   Thanks


Solution 1:

This solution will work, I tested it:

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

Solution 2:

Not tested, but if you use something like:

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

That should remove all spaces.

UPDATE

To remove all spaces and &nbsp; references, use something like:

$string = preg_replace("/\s|&nbsp;/",'',$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);