我需要在iframe

时间:2017-12-19 20:18:33

标签: php iframe

<iframe src="https://player.vimeo.com/video/322332324?byline=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

我需要从src中提取数字..我需要得到322332324.无论有多少位数。

此代码将获取src,但如何获取数字

preg_match(&#39; / src =&#34;([^&#34;] +)&#34; /&#39;,$ iframe_string,$ match); $ url = $ match [1];

1 个答案:

答案 0 :(得分:0)

假设数字始终是URL的最后一部分,您可以这样做:

备选方案1

$url = 'https://player.vimeo.com/video/322332324?byline=0';

// Extract the path from the URL
$path = parse_url($url, PHP_URL_PATH);

// Explode the path on / to get the different fragments
$fragments = explode('/', $path);

// Now simply take the last part of the fragemnts
$numbers = end($fragments);

演示:https://3v4l.org/TI1El

备选方案2

如果你想要更少的代码,你可以跳过爆炸部分,只有substr()和strrpos()。代码少但冗长:

$url = 'https://player.vimeo.com/video/322332324?byline=0';

// Get the path from the URL
$path = parse_url($url, PHP_URL_PATH);

// Get the everything after the last slash
$numbers = substr($path, strrpos($path, '/') + 1);

演示:https://3v4l.org/aRjfc