且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Php/MySql 在 json 中查找/替换 utf-8 字符串

更新时间:2023-11-27 11:34:52

您需要放置转义序列来实现此目的.在 Mysql 中,涉及到第二层转义.所以用这个

You need to put escape sequence to achieve this. In Mysql, there is a second layer of escaping involved. So use this

SELECT * FROM `wp_postmeta` WHERE `meta_value` LIKE '%\\\\u067e\\\\u062f\\\\u0631\\\\u0627\\\\u0645%'

要自动搜索和替换斜线,请使用此

To automatically search and replace slash, use this

<?php
$keyword_j = "\u067e\u062f\u0631\u0627\u0645";
$x = str_replace("\\", "\\\\\\\\", $keyword_j);
echo $x;
?>

更新查询

$str = addslashes(htmlentities("<a href='".$link."'>".$keyword_j."</a>"));

$sql2 = "UPDATE wp_postmeta SET meta_value ='".$str."' WHERE meta_value LIKE '%".$x."%'";