Home  >  Article  >  Backend Development  >  Solve the problem of Chinese json encoding fuzzy query in php

Solve the problem of Chinese json encoding fuzzy query in php

WBOY
WBOYOriginal
2016-08-08 09:25:341089browse

json格式中文解码查询

这里有一坑,mysql 在查询的时候自动将'\' 做特殊字符处理了

需要四个 \\\\ 进行转换转义

$username = json_encode($username);
$username = str_replace('\\','\\\\\\\\',trim($username, '"'));
$where = $where . ' and wb_bp_users.`name` like \'%' . $username . '%\'';

详细信息可参考这问仁兄的博客:

http://my.oschina.net/qii/blog/196532

以上就介绍了php中解决中文json编码模糊查询问题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:thinkphp jumpNext article:thinkphp jump