2014-01-23 20 views
0

我想從內容位DailyMotion視頻網址和視頻ID多個匹配下面正則表達式匹配還有Vimeo嵌入網址的所有域和視頻的標識

<iframe style="clear: both; display: block;" 
src="//www.dailymotion.com/embed/video/x1a6ldm" 
height="315" width="420" allowfullscreen="" frameborder="0"></iframe> 
<iframe style="clear: both; display: block;" 
src="//www.dailymotion.com/embed/video/x1a6k8x" 
height="315" width="420" allowfullscreen="" frameborder="0"></iframe> 
<iframe style="clear: both; display: block;" 
src="//www.dailymotion.com/embed/video/x1a6k1i" 
height="315" width="420" allowfullscreen="" frameborder="0"></iframe> 

我想下面的所有代碼,但我沒有一個工作

preg_match_all ("/^.+dailymotion.com\/(video|embed\/video)\/([^_]+)[^#]*(#video=([^_&]+))?/", $content, $dailymotionmatches, PREG_SET_ORDER); 

preg_match_all ("/http:\/\/www\.dailymotion\.com\/video\/([^_]+)/", $content , $dailymotionmatches, PREG_SET_ORDER); 

preg_match_all ('/http:\/\/www\.dailymotion\.com\/video\/([^_]+)/', $content , $dailymotionmatches, PREG_SET_ORDER); 

我也嘗試了最大的問題在stackoverflow,但沒有找到任何解決方案,我的情況。我對正則表達式很陌生。

我測試它here

+0

[解析器](http://simplehtmldom.sourceforge.net)。提取鏈接。用正則表達式測試網址。你也可以使用[parse_url](http://php.net/parse_url)。 – tenub

+0

@tenub謝謝你的建議,但我需要regax! –

+0

'。* dailymotion \ .com \/embed \/video \/[a-z0-9] +' – tenub

回答

1

以下的正則表達式似乎很好地工作。根據你的代碼的使用

(www\.dailymotion.com\/embed\/video\/.*?)" 

http://www.phpliveregex.com/p/3gO

例子:

preg_match_all ('(www\.dailymotion.com\/embed\/video\/.*?)"', $content, $dailymotionmatches, PREG_SET_ORDER); 

更新

搶視頻ID本身,使用下面的正則表達式

(www\.dailymotion.com/embed/video/(.*?))" 

preg_match_all ('(www\.dailymotion.com\/embed\/video\/.*?)"', $content, $dailymotionmatches, PREG_SET_ORDER); 

並且視頻ID將作爲結果位置中的數組2

相關問題