使用 preg match 过滤掉 iframe

发布于 2024-11-27 14:02:25 字数 786 浏览 0 评论 0原文

我正在尝试过滤掉帖子中的 iframe,我的帖子看起来像这样,

<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe><!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don.  (New Album Coming Soon!)

我只想返回 iframe 而不是帖子描述,所以 from 就是我想要的。

谢谢

I'm trying to filter out the iframe in my post, my post looks like this

<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe><!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don.  (New Album Coming Soon!)

I would just like to return the iframe not the post description, so from is what I want.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可可 2024-12-04 14:02:25
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $string, $matches);
echo ($matches[0]); //only the <iframe ...></iframe> part
echo ($matches[1]); //the src part. (http://www.youtube.com/embed/IIYeKGNNNf4?rel=0)
preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $string, $matches);
echo ($matches[0]); //only the <iframe ...></iframe> part
echo ($matches[1]); //the src part. (http://www.youtube.com/embed/IIYeKGNNNf4?rel=0)
路弥 2024-12-04 14:02:25

我一次又一次地看到同​​样的错误,使用正则表达式来解析 html,使用 HTML DOM 解析器< /a>

include("simple_html_dom.php") ;
$string = <<< EOF
"<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe>
<!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don. (New Album Coming Soon!)"
EOF;

$html = str_get_html($string);     
foreach($html->find('iframe') as $element)
{
       echo $element->src . '<br>';
}

输出:

http://www.youtube.com/embed/IIYeKGNNNf4?rel=0< /a>


I see the same error over and over again, using regex to parse html, USE A HTML DOM PARSER.

include("simple_html_dom.php") ;
$string = <<< EOF
"<!--videoplayer--><iframe title="YouTube video player" class="youtube-player" type="text/html" width="200" height="200" src="http://www.youtube.com/embed/IIYeKGNNNf4?rel=0" frameborder="0" allowFullScreen></iframe>
<!--endvideoplayer-->Blitz performs at Desifest 2010 in Toronto Canada, & Films music video with Navin Kundra for the song "Love You The Same" feat Kat Eyez & produced by Roach Killa from Blitz's new album "Get Blitz". Join my fanpage for more: WWW.FACEBOOK.COM/BLITZMUSIC *Special thanks to: Deesha, Dj Jump Off, Paul The Drummer, Surgeon, Umar, Navin Kundra, Nyrone, Sats B, Kat Eyez, B Don. (New Album Coming Soon!)"
EOF;

$html = str_get_html($string);     
foreach($html->find('iframe') as $element)
{
       echo $element->src . '<br>';
}

outputs :

http://www.youtube.com/embed/IIYeKGNNNf4?rel=0

遗忘曾经 2024-12-04 14:02:25
preg_match('#<iframe(.*?)></iframe>#is', $string, $matches);
echo $matches[1]; // 0 for <iframe></iframe> part.
preg_match('#<iframe(.*?)></iframe>#is', $string, $matches);
echo $matches[1]; // 0 for <iframe></iframe> part.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文