我在我的 wordpress 页面上有这个 youtube 的嵌入 iframe。
所以我正在重新创建每个嵌入帧,我只需要留下两件事:src 和 image
我有用于获取 src 的正则表达式:
function youtube($html) {
if (strpos($html, "<iframe" ) !== false) {
$frame = preg_match('/<iframe.*?\/iframe>/i', $html, $match2);
$count = preg_match('/src=(["\'])(.*?)\1/', $match2[0], $match);
var_dump($match);
} else {
return $html;
}
}
add_filter('bp_get_activity_content_body', 'youtube', 10);
add_filter('the_excerpt', 'youtube', 10);
add_filter('the_content', 'youtube', 10);
所以$match
包含我的 src。但我用图像堆叠,这是一个 iframe(我还删除了脚本部分,我认为这不会做太多)
<iframe width="591" height="332" src="http://www.youtube.com/embed/1lws4QPUL7I?feature=oembed" frameborder="0" allowfullscreen="">
#document
<html lang="en" dir="ltr" data-cast-api-enabled="true">
<head>
<title>Craig Ferguson 2013 06 20 Lewis Black, Matt Morales - YouTube</title>
<link rel="canonical" href="http://www.youtube.com/watch?v=1lws4QPUL7I">
<link id="css-1394124665" class="www-embed-player" rel="stylesheet" href="http://s.ytimg.com/yts/cssbin/www-embed-player-webp-vflC5nNwO.css" data-loaded="true">
</head>
<body id="" class="date-20130829 en_US ltr ytg-old-clearfix site-left-aligned exp-watch7-comment-ui webkit webkit-537" dir="ltr">
<div id="player" class="full-frame" style="width: 100%; height: 100%; overflow: hidden;">
<embed name="player1" height="100%" width="100%" id="player1" tabindex="0" type="application/x-shockwave-flash" src="http://s.ytimg.com/yts/swfbin/watch_as3-vfldizVp8.swf" allowscriptaccess="always" allowfullscreen="true" bgcolor="#000000" flashvars="user_display_name=Radikal%20Edward&iurl=http%3A%2F%2Fi1.ytimg.com%2Fvi%2F1lws4QPUL7I%2Fhqdefault.jpg&ldpj=-10&thumbnail_num_shards=1&rel=1&authuser=0&hl=en_US&probably_logged_in=1&iurlsd=http%3A%2F%2Fi1.ytimg.com%2Fvi%2F1lws4QPUL7I%2Fsddefault.jpg&length_seconds=2376&idpj=-2&cr=US&video_id=1lws4QPUL7I&is_html5_mobile_device=false&user_display_image=https%3A%2F%2Flh4.googleusercontent.com%2F-PcXCu3dRJSk%2FAAAAAAAAAAI%2FAAAAAAAAAAA%2FoIo6fJTO2X4%2Fs28-c-k%2Fphoto.jpg&allow_ratings=1&iurlmaxres=http%3A%2F%2Fi1.ytimg.com%2Fvi%2F1lws4QPUL7I%2Fmaxresdefault.jpg&fexp=939106%2C929117%2C929121%2C929906%2C929907%2C929922%2C929127%2C929129%2C929131%2C929930%2C936403%2C925726%2C925720%2C925722%2C925718%2C929917%2C906945%2C929933%2C920302%2C906842%2C913428%2C920605%2C919811%2C904830%2C919373%2C930803%2C908536%2C904122%2C938701%2C936308%2C909549%2C900816%2C912711%2C904494%2C904497%2C900375%2C906001&view_count=260&endscreen_module=http%3A%2F%2Fs.ytimg.com%2Fyts%2Fswfbin%2Fendscreen-vfl2YNgK7.swf&playlist_module=http%3A%2F%2Fs.ytimg.com%2Fyts%2Fswfbin%2Fplaylist_module-vflie7hg5.swf&enablejsapi=1&avg_rating=5&allow_embed=1&el=embedded&sk=puClsWoCKB-tDaeZo-YHXBSb1UkBB1wuC&feature=oembed&share_icons=http%3A%2F%2Fs.ytimg.com%2Fyts%2Fswfbin%2Fsharing-vflF4tO1T.swf&title=Craig%20Ferguson%20%20%202013%2006%2020%20%20%20Lewis%20Black%2C%20Matt...&sendtmp=1&abd=1&eurl=http%3A%2F%2Flocaldollars.ge%2F&playerapiid=player1&framer=http%3A%2F%2Flocaldollars.ge%2F">
</div>
</body>
</html>
</iframe>
而且在我的功能的第一部分,我想检查 iframe 是否属于 youtube(因为我也有不同的),我只检查 iframe
if (strpos($html, "<iframe" ) !== false)
我没有想出正则表达式,因为宽度和高度可能会改变