I want to grab the last dynamic numbers of an external URL.
https://data.aboss.com/v1/agency/1001/101010/events/xxxxxx
$url = https://data.aboss.com/v1/agency/1001/101010/events/;
$value = substr($url, strrpos($url, '/') + 1);
value="<?php echo $value; ?>"
result should be xxxxxx.
2
Answers
To get the last part from the url, you can use
parse_url()
andpathinfo()
function in PHP. Try following code,There are many ways to do this, the simplest one-liner would be to use explode:
Or if something may come after ‘events/xxxxxx’:
You can also use a regex with
preg_match
:Sandbox