Reputation: 65
So I have a string (that is dynamic). It is $url.. now the URL string can sometimes look like this: http://site.com/blah123
or
http://site.com/blah123?blahblah
right now I have it doing
preg_match("/site.com\/(.*)/",$info[url],$matches);
$gethash = $matches[1];
but it gets thrown off when there is a ? mark statement afterwords.
How can I have it grab justeverything between the slash (/) and the question mark, when there IS a question mark, but when there ISN'T a question mark, just grab everything after the slash (/)
Upvotes: 0
Views: 1903
Reputation: 224942
Just exclude ?
:
preg_match('/site\.com\/([^?]*)/', $info[url], $matches);
Upvotes: 3