您的位置:首页 > Web前端 > HTML

htmlentities()函数 中文转成乱码问题

2017-05-27 22:15 190 查看
htmlentities — Convert all applicable characters to HTML entities
string htmlentities    ( string 
$string
[, int
$flags
= ENT_COMPAT | ENT_HTML401 [, string
$encoding
= 'UTF-8' [, bool
$double_encode
= true ]]] )
对于中文如果不指定第三个参数的话,中文就被转成乱码,解决方法就是把第二、第三个参数(UTF-8或GBK)都指定了。
echo htmlentities("高振安",ENT_NOQUOTES,GB2312)
echo htmlentities("高振安",ENT_NOQUOTES,"utf-8")

附 第二个参数可选值:
ENT_COMPATWill convert double-quotes and leave single-quotes alone.
ENT_QUOTESWill convert both double and single quotes.
ENT_NOQUOTESWill leave both double and single quotes unconverted.
ENT_IGNORESilently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it ? may have security implications.
ENT_SUBSTITUTEReplace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of returning an empty string.
ENT_DISALLOWEDReplace invalid code points for the given document type with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of leaving them as is. This may be useful, for instance, to ensure the well-formedness of XML documents with embedded external content.
ENT_HTML401Handle code as HTML 4.01.
ENT_XML1Handle code as XML 1.
ENT_XHTMLHandle code as XHTML.
ENT_HTML5Handle code as HTML 5. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: