Search code examples
phpstringreplacesanitization

Remove hash symbols from string (str_replace() doesn't modify by reference)


How can I remove all hashes from a string with PHP?

I've tried str_replace("#","",$message), but it didn't work.


Solution

  • Remember that str_replace() return replaced text.

    Example:

    $a = '### Foo ###';
    $a = str_replace('#', '', $a);
    echo $a;
    

    DEMO