php method to convert utf8 to gbk: first create a PHP sample file; then set the header; finally use "iconv("UTF-8","gbk//TRANSLIT",$str);" The encoding of the string can be converted from UTF8 to GB2312.
Recommended: "PHP Video Tutorial"
php converts utf8 to gbk
code As follows:
<?php header("Content-type:text/html;charset=UTF-8"); echo $str= '你好,这里是卖咖啡!'; echo '<br />'; echo iconv("UTF-8","gbk//TRANSLIT",$str); //将字符串的编码从UTF-8转到GB2312
Related introduction:
iconv_get_encoding — Get the internal configuration variables of the iconv extension
iconv_mime_decode_headers — Decode multiple MIME header fields at one time
iconv_mime_decode — Decodes a MIME header field
iconv_mime_encode — Composes a MIME header field Character count statistics
iconv_strpos — Finds position of first occurrence of a needle within a haystack
iconv_strrpos — Finds the last occurrence of a needle within a haystack
iconv_substr — Intercept characters Part of the string
iconv — Convert the string to the required character encoding
ob_iconv_handler — Convert the character encoding using the output buffer handler
The above is the detailed content of How to convert utf8 to gbk in php. For more information, please follow other related articles on the PHP Chinese website!