php修剪掉了不受欢迎的文本

时间:2012-04-30 05:56:28

标签: php

我在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>

2 个答案:

答案 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删除文字