bv.ebizzinfotech
bv.ebizzinfotech

Reputation: 62

preg_match rejects the character '|'

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

Answers (1)

sectus
sectus

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

Related Questions