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

htmlentitiesConvert 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_COMPAT Will convert double-quotes and leave single-quotes alone.
ENT_QUOTES Will convert both double and single quotes.
ENT_NOQUOTES Will leave both double and single quotes unconverted.
ENT_IGNORE Silently discard invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it ? may have security implications.
ENT_SUBSTITUTE Replace invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of returning an empty string.
ENT_DISALLOWED Replace 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_HTML401 Handle code as HTML 4.01.
ENT_XML1 Handle code as XML 1.
ENT_XHTML Handle code as XHTML.
ENT_HTML5 Handle code as HTML 5. 

你可能感兴趣的:(PHP)