replace   characters that are hidden in text

后端 未结 4 521
傲寒
傲寒 2020-12-07 13:35

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

  • hold UNICODE characters
  • hold
    tag
相关标签:
4条回答
  • 2020-12-07 13:42

    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);
    
    0 讨论(0)
  • 2020-12-07 13:55

    This solution will work, I tested it:

    $string = htmlentities($content, null, 'utf-8');
    $content = str_replace(" ", "", $string);
    $content = html_entity_decode($content);
    
    0 讨论(0)
  • 2020-12-07 13:57

    This worked for me.

    preg_replace("/ /",'',$string)

    0 讨论(0)
  • 2020-12-07 14:04

    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

    0 讨论(0)
提交回复
热议问题