Home > Backend Development > PHP Problem > How to convert utf8 to gbk in php

How to convert utf8 to gbk in php

藏色散人
Release: 2023-03-07 12:22:01
Original
3170 people have browsed it

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
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template