This question already has an answer here:
I am getting the error:
Warning: preg_match() [function.preg-match]: Unknown modifier '[' in /sample.php on line 71
Every time I'm try to run my script.
The code at line 71 is:
if(!preg_match("[h][t][t][p][:][/][/][a-zA-Z0-9\]",$link))
Please help me in fixing this issue..
</div>
You need delimiters and few modifications in pattern:
preg_match("/http:\/\/[a-zA-Z0-9\\\\]/",$link)
/pattern/
[ ]
\
, you should escape with \
so \\\\
[Read this SO answer to know why you need three backslash to escape a backslash]Your regex is overly complex (and lacking delimiters, which is your main issue). To match a literal character you don't need a character class, unless it is a special character (also depending on the character might still need to be escaped or positioned differently), a range of characters, or multiple alternative characters.
e.g.
[aeiou]
would allow for a vowel,
[aeiou]+
would allow for multiple vowels.
This regex:
~http://[a-zA-Z0-9]~
Should match http://
and then an alphanumerical character. The ~
s are delimiters.
PHP usage:
if(!preg_match('~http://[a-zA-Z0-9]~',$link))