Home  >  Article  >  Backend Development  >  用htmlentities 中文转utf-8有关问题

用htmlentities 中文转utf-8有关问题

WBOY
WBOYOriginal
2016-06-13 11:09:331043browse

用htmlentities 中文转utf-8问题
$str="中文";
echo json_encode($str);

显示为:
[null] 

所以打算用htmlentities 转一下:
$str=htmlentities($str,utf-8);
echo json_encode($str);

结果出现一个很郁闷的问题
Notice: Use of undefined constant utf - assumed 'utf' in F:\工作\test.php on line 24

["\ufffd\ufffd\ufffd\u052a\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\uccef\ufffd\ufffd\ufffd\ufffd\u3d22\ufffd\ufffd "] 


line 24:$str=htmlentities($str,utf-8);

看结果转换成功了  ,但是不知道为什么 报错了!
------解决方案--------------------
参数要用引号啊,另外为何不用iconv,这样转有问题吧?

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