我正在尝试将<iframe>
wordpress 博客中引用 Youtube 的标签替换为 this [youtube id='THEYOUTUBEID' width='600' height='350']
。我使用简单的 HTML DOM 解析器。虽然我做到了,但它并没有保存到每个帖子中。
谁能帮我理解我错在哪里?
$result = mysql_query("SELECT `post_content` FROM `wp_posts` WHERE `post_content` LIKE '<iframe%' ");
while($row = mysql_fetch_array($result)) {
$postContent = str_get_html($row["post_content"]);
foreach($postContent->find("iframe") as $iframe) {
$src = $iframe->src;
$last = substr( $src, strrpos( $src, '/' )+1 );
if (stripos($src, "youtube")) {
$neway = "[youtube id='".$last."' width='600' height='350']";
} elseif (stripos($src, "vimeo")) {
$neway = "[vimeo id='".$last."' width='600' height='350']";
}
$iframe->outertext = $neway;
}
}