Possible Duplicate:
Converting ereg expressions to preg
http://www.google.co.in/aclk?sa=
L&ai=C_jFQq_
http://www.google.co.in/aclk?sa=
l&ai=CKKCUg
The highlighted part is common in my url.
My Regex
if (preg_match('google.com/aclk\?sa\=L\&ai/i', $url))
Is this regex correct? I want to match my regex to my url.
You've forgotten the delimiters:
if (preg_match('#google.com/aclk\?sa\=L\&ai/i#', $url))
^-- ^--
Traditionally they're /
, but since you're working on a URL, this is a case where it makes sense to use a different character, and I've chose #
in this case.
It's unclear if that last /i
is an actual delimiter and the case-insensitve flag, so I've left that in place as part of the pattern.
Delimiter must not be alphanumeric or backslash, that is your error.