Home  >  Article  >  Backend Development  >  How to convert utf8 to gbk in php

How to convert utf8 to gbk in php

藏色散人
藏色散人Original
2020-11-06 10:10:143113browse

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.

How to convert utf8 to gbk in php

Recommended: "PHP Video Tutorial"

php converts utf8 to gbk

code As follows:

<?php
header("Content-type:text/html;charset=UTF-8");
echo $str= &#39;你好,这里是卖咖啡!&#39;;
echo &#39;<br />&#39;;
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!

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