PHP detects the current character encoding and transcoding-php Tutorial

Source: Internet
Author: User
PHP detects the current character encoding and transcode 1. detects the current string encoding and changes the encoding to UTF-8

1. obtain the encoding of the current string.

$ Encode = mb_detect_encoding ($ str, array ("ASCII", 'utf-8', "GB2312", "GBK", 'big5 '));

2. change the character encoding to UTF-8.

$ Str_encode = mb_convert_encoding ($ str, 'utf-8', $ encode );


II. Function Details

1Mb_detect_encoding?Encoding of detected characters

Description

String mb_detect_encoding (string $ str [, mixed $ encoding_list = mb_detect_order () [, bool $ strict = false])

Checks the str encoding of a string.

Parameter str

The string to be checked.

Encoding_list

Encoding_list is a character encoding list. The encoding sequence can be specified by list strings separated by arrays or commas.

If encoding_list is omitted, detect_order is used.

Strict

Strict specifies whether the encoding is strictly checked. The default value is FALSE.

Return value

The detected character encoding, or FALSE is returned if the encoding of the specified string cannot be detected.

2Mb_convert_encoding?Conversion character encoding

Description

String mb_convert_encoding (string $ str, string $ to_encoding [, mixed $ from_encoding = mb_internal_encoding ()])

Convert the string-type str character encoding from the optional from_encoding to to_encoding.

Parameter str

The string to be encoded.

To_encoding

The encoding type to convert str.

From_encoding

Before conversion, use the character code name. It can be an array or a comma-separated enumerated list. If from_encoding is not provided, internal (internal) encoding is used.

See supported encoding.

Return value

The encoded string.

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.