php简单的html DOM解析器结果不保存

问题描述:

我试图用指代Youtube,wordpress博客的标签替换[youtube id='THEYOUTUBEID' width='600' height='350']。我使用简单的HTML DOM解析器。尽管我做到了,但并没有保存到每一篇文章中。php简单的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; 

    } 
} 
+1

你问为什么它没有保存到数据库?因为代码中没有查询将新信息发送回上游数据库,除非您的$ iframe对象在您设置其纯文本属性时自动处理它... – rdlowrey

+0

不,iframe对象不会这样做。我认为它确实是愚蠢的。现在我明白我必须有更新查询才能保存它... – nasia

看来你忘记保存更改SQLDB ..你也忘了得到一个唯一标识表.. 首先编辑$结果

$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; 
}