0

我正在尝试将<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;

     } 
 }
4

1 回答 1

0

似乎您忘记将更改保存到 sqldb ..您也忘记获取表的唯一标识符..首先将 $result 编辑为

$result = mysql_query("SELECT `id`,`post_content`  FROM `wp_posts` WHERE `post_content` LIKE '<iframe%' ");

然后插入这个

mysql_query('UPDATE `wp_posts`  SET `post_content` = \''.mysql_real_escape_string($postContent->save()).'\' WHERE `id` = '.$row["id"]);

在这之后

 $iframe->outertext = $neway;
 }
于 2014-01-20T01:09:28.467 回答