【问题标题】:How to replace » "Right angle quotation mark" with MySQL如何用 MySQL 替换 » “直角引号”
【发布时间】:2021-02-17 12:02:40
【问题描述】:

我正在使用那个 MySQL 查询来格式化我的 wordpress 帖子。它对于像 " 和其他字符非常有效,但不适用于 "»"。我进行了研究以解决这个问题,但我没有找到解决方案,在 stackoverflow 上也没有。

当我执行这段代码时,什么也没发生。

$query = "UPDATE wp_posts SET post_content = REPLACE(post_content, '»<br />', '»\n\n')";

我试过了

$query = "UPDATE wp_posts SET post_content = REPLACE(post_content, '\»<br />', '\»\n\n')";

还有那个

$query = "UPDATE wp_posts SET post_content = REPLACE(post_content, '&raquo;<br />', '&raquo;\n\n')";

它不工作。

【问题讨论】:

  • 您可以使用占位符值吗?如果是这样,这应该很容易做到。将其编码在双引号字符串中会使 SQL 语句变得混乱。考虑REPLACE(content, ?, ?),然后绑定这两个参数。

标签: mysql replace


【解决方案1】:

你必须转义\n

CREATE TABLE wp_posts (post_content varchar(29))
INSERT INTO wp_posts VALUES('a»<br />b')
UPDATE wp_posts SET post_content = REPLACE(post_content, '»<br />', '»\\n\\n')
SELECT * FROM wp_posts
| post_content | | :----------- | |一个»\n\nb |

db小提琴here

【讨论】:

  • 我不认为文字 反斜杠 n 是这里想要的结果。
  • 感谢您的回答,您的解决方案对我不起作用。我会尝试 $conn->set_charset("utf8");也许这有帮助
  • 是的,如果你有 utf8 那么utf8 all the way through 是唯一的方法
  • 这是有效的 $query = "UPDATE wp_posts SET post_content = REPLACE(post_content, '»
    ', '»\n\n')";当我设置 mysqli_set_charset($conn,"utf8");
  • 留下双倍的\,因为它们不会伤害你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-01
  • 1970-01-01
  • 2011-02-06
  • 2010-09-24
  • 2014-02-19
  • 1970-01-01
相关资源
最近更新 更多