Php Character Set conversion, php Character Set

Source: Internet
Author: User

Php Character Set conversion, php Character Set

PHP uses iconv to convert a string from gbk to the UTF8 character set.

1. iconv () Introduction

The iconv function can convert a known character set file to another known character set file. Example: Convert from GB2312 to UTF-8.

The iconv function is built in php5. The GB character set is enabled by default.

2. iconv () Error

Iconv will encounter an error when converting the characters "-" To gb2312. The solution is to add "// IGNORE" after the encoding to be converted, that is, after the second parameter of the iconv function:

Iconv ("UTF-8", "GB2312 // IGNORE", $ data)

Ignore indicates that the conversion error is ignored. Without the ignore parameter, all strings after this character cannot be saved.

3. iconv () Example

<? Php echo $ str = 'Hello, I am selling coffee! '; Echo' <br/> '; echo iconv ('gb2312', 'utf-8', $ str ); // encode the string from GB2312 to the UTF-8 echo '<br/>'; echo iconv_substr ($ str, 1, 1, 'utf-8 '); // capture by the number of characters rather than the byte print_r (iconv_get_encoding (); // obtain the current page encoding information echo iconv_strlen ($ str, 'utf-8 '); // get the length of the specified encoded string?>

The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.