PHP-从IFrame获取URL?

我希望允许用户添加视频,但是其中一个站点存在问题.

我将允许来自Youtube,Vimeo,Vevo,Daily Motion和MTV的视频.

问题是对于MTV. URL总是不同的,所以我想知道是否有办法获取IFrame /嵌入代码的源值.

示例:MTV嵌入代码为:

<div style="background-color:#000000;width:520px;">
<div style="padding:4px;">
<iframe src="http://media.mtvnservices.com/embed/mgid:uma:videolist:mtv.com:1687162/cp~instance%3Dfullepisode%26autoPlay%3Dfalse%26series%3D2211%26seriesId%3D29240%26channelId%3D1%26id%3D1687162%26instance%3Dfullepisode%26uri%3Dmgid%3Auma%3Avideolist%3Amtv.com%3A1687162" width="512" height="288" frameborder="0"></iframe>
<p style="text-align:left;background-color:#FFFFFF;padding:4px;margin-top:4px;margin-bottom:0px;font-family:Arial, Helvetica, sans-serif;font-size:12px;">Get More: 
    <a href="http://www.mtv.com/shows/teen_mom/season_4/series.jhtml" style="color:#439CD8;" target="_blank">Teen Mom (Season 4)</a>, <a href="http://www.mtv.com/videos/home.jhtml" style="color:#439CD8;" target="_blank">Full Episodes</a></p></div></div>

有没有办法从完整的字符串中获取IFrame源值?

我只是想 :

http://media.mtvnservices.com/embed/mgid:uma:videolist:mtv.com:1687162/cp~instance%3Dfullepisode%26autoPlay%3Dfalse%26series%3D2211%26seriesId%3D29240%26channelId%3D1%26id%3D1687162%26instance%3Dfullepisode%26uri%3Dmgid%3Auma%3Avideolist%3Amtv.com%3A1687162

任何帮助,将不胜感激.其他视频源很简单,因为我可以使用物理URL本身而不是嵌入代码.

解决方法:

这是有效的HTML,因此您可以轻松地使用SimpleXML进行解析:

$root = simplexml_load_string($embed_code);
$url = (string) $root->div->iframe['src'];
上一篇:SpringBoot使用JSP


下一篇:java-轻松将python导出到没有解释器的人