Behnam Behnam - 12 days ago 9
PHP Question

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

FINAL SOLUTION:

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

Answer

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);