>  기사  >  백엔드 개발  >  用htmlentities 中文转utf-8问题

用htmlentities 中文转utf-8问题

WBOY
WBOY원래의
2016-06-23 14:03:201614검색

$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,这样转有问题吧?

加引号试过了
即报错 又是[null] 

$_title=htmlentities($_title,"utf-8");

iconv我试试看

您没有第2 个参数

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.