Ive得到了如下功能都包装iframe的在一个div类=“视频容器”PHP/WordPress的的preg_match
我想要的目标仅包含一个src与SRC =“www.youtube开始的I帧
有没有修改这个功能做更具体的办法?在此先
感谢。
function div_wrapper($content) {
// match any iframes
$pattern = '~<iframe.*</iframe>~';
preg_match_all($pattern, $content, $matches);
foreach ($matches[0] as $match) {
// wrap matched iframe with div
$wrappedframe = '<div class="video-container">' . $match . '</div>';
//replace original iframe with new in content
$content = str_replace($match, $wrappedframe, $content);
}
return $content;
}
add_filter('the_content', 'div_wrapper');
'if(!condition)continue;'在foreach中作为第一行。使条件成为目标条件(src以任何形式开始) – Patashu