修复数据库中被SyntaxHighlighter替换的特殊符号

< > " & '修改自http://quartergeek.com/fix-special-char-replaced-by-syntaxhighlighter

代码增加了单引号的替换,同时增加几个变量提醒用户修改。

自从换上了Crayon Syntax Highlighter,发现原来<>&”’符号被WP替换成了<  > " & ‘而Crayon Syntax Highlighter又不能转换,只好转回来,于是写了下面这个脚本,成功地替换回来了。

set_charset("utf8");
$result = $conn->query("SELECT post_content, ID FROM ".$ta);
$stmt = $conn->prepare("UPDATE ".$ta." SET post_content = ? WHERE ID = ?"); 

$search  = array("<", ">", """, "&", "'");
$replace = array("<"   , ">"   , "\""    , "&"    ,"'");
while ($row = $result->fetch_array())
{
  $id = $row['ID'];
  $post_content = str_replace($search, $replace, $row['post_content']);
  $stmt->bind_param('si', $post_content, $id);
  if (!$stmt->execute())
  {
    die("\n[ERROR!]".$id."\n");
  }
  else
  {
    echo "[Success]".$id."\n";
  }
}

$result->free();
$conn->close();
?>

 

CC BY-NC-SA 4.0 修复数据库中被SyntaxHighlighter替换的特殊符号 by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据