Here’s one that should be simple. I need to find only the numbers from the link to return the video. The numbers I need are shown in bold. Sometimes there are fewer numbers and I’m guessing with time there will be more.
<iframe src="http://somesight.com/userfiles/[b]49280655[/b]?title=0&byline=0&portrait=0Why not with substr? Here’s 3 examples:
[php]
$uri = “http://somesight.com/userfiles/49280655?title=0&byline=0&portrait=0”;
$path = parse_url($uri, PHP_URL_PATH);
echo substr(strrchr($path, ‘/’), 1); // 49280655
[/php]
[php]
$uri = “http://somesight.com/userfiles/49280655?title=0&byline=0&portrait=0”;
$part = substr($uri, strrpos($uri, ‘/’) + 1);
echo substr($part, 0, strpos($part, ‘?’)); // 49280655
[/php]
[php]
$uri = “http://somesight.com/userfiles/49280655?title=0&byline=0&portrait=0”;
preg_match(’//(\d+)?/’, $uri, $parts);
echo $parts[1]; // 49280655
[/php]
I wanted not with substr to see what else I might be missing - how many other ways it can be done. In this case the regular expression match should be fine even if the site changes the directory. That’s the best answer. Thanks.
There is no difference really. Both substr and preg_match rely on the value to be between the forward slash and question mark. The best solution I think would be the first one. Using the PHP_URL_PATH since it doesn’t rely on the question mark.
If you want to get overly complicated, explode it first on the /, then explode that piece on the ?, that’ll give you the number.