剥离不需要的嵌入代码

时间:2013-12-23 09:18:21

标签: php iframe embed

我目前正在为一位朋友查看一段代码,我正在尝试删除一段不需要的代码但不确定如何实现我想要的代码。

CODE:

<?php

$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281"
 frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> 
<p><a href="http://vimeo.com/82444237">KING OF THE BEASTS</a> from 
<a href="http://vimeo.com/deltoidjohn">John Wiley</a> on 
<a href="https://vimeo.com">Vimeo</a>.</p>';


echo($blah);
?>

在此代码中,网站显示:from on

我希望输入的起点是iframe,端点是/ iframe。

如果没有手动确定只选择了iframe,有关如何实现此目的的任何建议吗?

3 个答案:

答案 0 :(得分:1)

试试这个:

function blah($postTag)
{

//TERMINATES THE STRING AT </IFRAME>
$exploder = explode("iframe",$postTag);

//CALLS THE STRING UNTIL THE FIRST IFRAME INPUT AND CLOSES THE IFRAME TAG
$cleaned =  "<iframe".$exploder[1]."iframe>";

return $cleaned; 
}

$blahblah = blah('<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/82444237">KING OF THE BEASTS</a> from <a href="http://vimeo.com/deltoidjohn">John Wiley</a> on <a href="https://vimeo.com">Vimeo</a>.</p>');

应该这样做。

答案 1 :(得分:0)

一个简单的strstr()将完成这项工作。

<?php
$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/82444237">KING OF THE BEASTS</a> from <a href="http://vimeo.com/deltoidjohn">John Wiley</a> on <a href="https://vimeo.com">Vimeo</a>.</p>';
echo strstr($blah,'</iframe>',true)."</iframe>";

输出

<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

答案 2 :(得分:0)

$blah = '<iframe src="//player.vimeo.com/video/82444237" width="500" height="281"  frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a  href="http://vimeo.com/82444237">KING OF THE BEASTS</a> from <a href="http://vimeo.com/deltoidjohn">John Wiley</a> on <a href="https://vimeo.com">Vimeo</a>.</p>';

echo substr($blah, 0, strpos($blah, '</iframe>')) ."</iframe>";

输出:

<iframe src="//player.vimeo.com/video/82444237" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>