2017-12-19 5 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를 얻을 것이다하지만 어떻게 난 그냥 숫자를 ('/ SRC = "([^"] +)'/ ', $의 iframe_string, $ 일치)

는 preg_match를받을 수 있나요; $의 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); 

데모 : 당신은 적은 코드를 원하는 경우 2

https://3v4l.org/TI1El

대체, 당신은 일부 단지 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 변경되지 않습니다 어떤 과학적 이해가있는 경우

+0

@IsmailMathkour - 문제가 해결되면 언제든지 알려주세요. 대답. –

관련 문제