Need to copy a specific text generated on page to a string in PHP
Solution:
Try this:
<?php
function getUrlPart($url = '') {
$urlarr = parse_url($url);
$split = explode('/', $urlarr['path']);
$c = 1;
while($split[count($split)-$c] == ''){
$c++;
}
return var_export($split[count($split)-$c], true);
}
$url = 'https://secure.nmi.com/api/v2/three-step/44505010//';
echo getUrlPart($url);
In this method you can get the route name at any depth, even with query parameters at the end.
Answer
Solution:
$yourUrl = 'https://secure.nmi.com/api/v2/three-step/44505010';
$reference = (int) explode('/', $yourUrl)[6];
This assumes the general URL format does not change.
Source