Reputation: 62
how to use preg match to see if special characters "|" exist in a string?
My current code is bellow
$string = "|preg_matchtest";
if (preg_match("/|/",$string))
{
echo "Succsess!!";
}
else
{
echo "failer";
}
it will print failer message in output.
Upvotes: 0
Views: 59
Reputation: 15464
Use backslash
preg_match("/\|/", $string)
Also you coud use preg_quote(there is list of special characters) function
$search_string = preg_quote('|');
preg_match("/".$search_string."/", $string)
Upvotes: 2