我试图剥离下面的代码
<iframe width="560" height="315" src="//www.youtube.com/embed/QUVdnzC19oU" frameborder="0" allowfullscreen></iframe>
它工作但没有正确剥离链接我得到的只是
http://img.youtube.com/vi/www.youtube.comembedQUVdnzC19oU/0.jpg
代替
http://img.youtube.com/vi/QUVdnzC19oU/0.jpg
请在下面找到 php 代码。
if(preg_match_all('@<iframe\s[^>]*src=[\"|\']([^\"\'\>]+)[^>].*?</iframe>@siu', $item->introtext, $iframesrc) >0){
if(isset($iframesrc[1])){
$vid = str_replace(
array(
'http://youtu.be/',
'http://www.youtube.com/embed/',
'http://youtube.googleapis.com/v/'), '', $iframesrc[1][0]);
$vid = preg_replace('@\/.*?@i', '', $vid);
if(!(empty($vid))){
$result = '' .
'<div class="vimage">
<a class="video-link vlink" href="'.$item->link.'" title="">
<img src="http://img.youtube.com/vi/'.$vid.'/0.jpg" />
<span class="play-icon"> </span>
</a>
</div>';
$item->introtext = str_replace($iframesrc['0'], '', $item->introtext);
}
}
}
提前致谢。