Search code examples
phpstringcharacterstrip

how to strip alt character code with php


I'm using this code to strip unwanted characters from a string, but I have a big problem with ALT+0160 character which is a non break space. I need to remove it as well

    $name = str_replace ("'", "", $name);

    $name = str_replace (""", '"', $name);

    $name = str_replace ("&", "&", $name);

    $name = str_replace ("<", "", $name);

    $name = str_replace (">", "", $name);

    $name = str_replace ("&", "_", $name);

    $name = str_replace ("*", "_", $name);

    $name = preg_replace('/[^ \p{L}\p{N} \@ \_ \- \.]/u', '', $name);

Solution

  • $name=str_replace(chr(0xc2a0),'',$name);