Hello!
Please help!
I'm on PHP. I have an url: 'http://example.com/articles/123a/view', how do I get '123a' only from this string with regular expression (preg_replace, probably). Can't figure it out. Thanks in advance.
Hello!
Please help!
I'm on PHP. I have an url: 'http://example.com/articles/123a/view', how do I get '123a' only from this string with regular expression (preg_replace, probably). Can't figure it out. Thanks in advance.
Try this regular expression:
^(?:[^/]*/){4}([^/]+)
preg_match('/^(?:[^\\/]*\\/){4}([^\\/]+)/', $str, $match)
$match[1]
will then hold your 123a
.
Why Regex?
$parts = explode('/', 'http://example.com/articles/123a/view');
echo $parts[4];