Baptiste Arnaud Baptiste Arnaud - 5 months ago 10
PHP Question

how to verify that a string contains a character

$string = "#hello";


I'm trying to have
hello
without the
#
. I also want a function to verify if the string contains the
#
.

str_replace("#", " ", $string);


and neither does

strstr($string,"#")


Any ideas ?

Answer

Compare the return value to the original.

if ($string != str_replace("#", "", $string)) 

See: http://php.net/manual/en/function.str-replace.php