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

私はsrcから数字を抽出する必要があります。何桁の数字があっても、私は322332324を取得する必要があります。私はiframeのURLの一部を抽出する必要があります

このコードは、SRCを取得しますが、どのように私はちょうど数

するpreg_match( '/ SRC = "([^"] +) "/'、$のiframe_string、$マッチ)取得ん。 $ URLを= $マッチ[1];

+0

を支援します。いずれかがあります?それらをリストアップできますか? – IncredibleHat

+0

[parse_url()](http://php.net/manual/en/function.parse-url.php)を使ってパスを取得し、 '/'で展開して最後の要素を取ることができます。 –

+0

これは常に同じです "src =" https://player.vimeo.com/video/ " –

答えて

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); 

デモ:変更されません任意のknownsがあるかどうhttps://3v4l.org/aRjfc

+0

@IsmailMathkour - 問題が解決した場合は、お気軽にご連絡ください。回答。 –

関連する問題