我在mysql数据库中有以下数据,这是来自u-tube的iframe: -
`<iframe width="560" height="315" src="http://www.youtube.com/embed/Om2fabTIKE4" frameborder="0" allowfullscreen></iframe>`
然而,在php代码中,上面的iframe存在一个当前阶段,我只需要将Om2fabTIKE4作为要填充的变量。
I would like to ask, is there any way that I can trim away
<iframe width="560" height="315" src="http://www.youtube.com/embed/
和
frameborder="0" allowfullscreen></iframe>
答案 0 :(得分:2)
试试这个:
$html = '<iframe width="560" height="315" src="http://www.youtube.com/embed/Om2fabTIKE4" frameborder="0" allowfullscreen></iframe>';
$dom = new DOMDocument();
$dom->loadHTML($html);
$tags = $dom->getElementsByTagName('iframe');
foreach ($tags as $tag)
$link = explode('/',parse_url($tag->getAttribute('src'),PHP_URL_PATH));
var_dump($link[2]);
您可以详细了解DOMDocument class here。
答案 1 :(得分:0)
使用str_replace删除文字