当我执行phpmyadmin时我的SQL代码工作,但是当我在我的php脚本中运行它时它不返回任何我认为它可能是编码(是utf8)所以我将其更改为ansi但没有区别。你们其中一个人可能会看到它有什么问题吗? (这是一个从Wordpress帖子中删除图像的脚本)
代码:
$query = "SELECT * FROM `wp_posts` where post_content like'%<img%\>'" or die("Error in the consult.." . mysqli_error($link));//THIS IS THE QUERY THAT DOES NOT WORK
$result = $link->query($query);
/*function filter($toFilter)
{
$pattern = "/<img.*?>/";
$filtered = "";
if(preg_match($pattern,$toFilter))
{
$filtered = preg_replace($pattern,'',$toFilter);
}
return (string)$filtered;
}
*/
while($row = mysqli_fetch_array($result)) {
$id = $row['ID'];
$toFilter = $row['post_content'];
$toFilter = (string)$toFilter;
$pattern = "/<img.*?>/";
$filtered = "";
if(preg_match($pattern,$toFilter))
{
$filtered = preg_replace($pattern,'',$toFilter);
}
$filtered = (string)$filtered;
$link->query("update wp_posts set post_content = $filtered where ID = $id;");
echo 'this works';
}
答案 0 :(得分:0)
'%<img%\>'
中逃避这个斜线(除非你的意思是逃避>
?)$pattern = "/<img.*?>/";
可能只是$pattern = "/<img.*>/";
。 *
表示0或更多,而?意味着可选,所以它非常冗余