Reputation: 349
I have a string returning a URL and need to figure out how to use if
and regex to do something whenever the returned URL contains a question mark.
So when $url is http://somedomain.com/?p=34325&blahblahblah
IF the $url contains "?p=
" (and discarding everything else) then exit, otherwise do something
Any help?
Many thanks
Upvotes: 4
Views: 10179
Reputation: 191749
You don't need a regex to match a simple string:
if (strpos($url, '?p=') !== false) {
exit;
}
//do something
If you really wanted to use a regex:
if (preg_match('/\?p=/', $url)) {
Upvotes: 9