In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
PHP transcoding function application skills, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
There are a large number of functions in PHP to support our application requirements. The function described below is about the PHP transcoding function. I hope it will be helpful to all of you. The mb_convert_encoding function is a multi-byte string encoding conversion function within PHP.
Can be in the need of use occasions (such as: to solve the problem of Chinese characters garbled generated by the use of Ajax in the GB2312 coding environment) to facilitate coding conversion, in order to solve the problem of webpage garbled, the use is very convenient, the efficiency is very high, almost all coding is supported. PHP 4 > = 4.0.6, supported by PHP 5 version.
Prototype of PHP transcoding function:
/ * *
* multibyte string encoding conversion function
*
* @ param string str string that needs to be converted
* @ param string to_encoding specifies the conversion to a certain encoding
, such as gb2312, gbk, utf-8, etc.
* @ param mixed from_encoding mixed to specify the encoding of the original string
, for example, specify mixed coding of JIS, eucjp-win and sjis-win at the same time
* @ return string
String mb_convert_encoding (string
Str, string to_encoding [, mixed from_encoding])
Examples of PHP transcoding functions are used:
1. Convert GBK encoded string to UTF-8 encoded string.
< ?PHP header("content-Type: text/html; charset=Utf-8"); echo mb_convert_encoding(" 你是我的好朋友", "UTF-8", "GBK"); ?>2. Convert UTF-8 encoded string to GB2312 encoded string.
/ / pay attention to saving this file as utf-8
Code format file retest
< ?PHP header("content-Type: text/html; charset=gb2312"); echo mb_convert_encoding(" 你是我的好朋友", "gb312", "utf-8"); ?>3. Convert the whole page
This method is suitable for all coding environments. In this way, all the character sets other than the first 128 characters (display characters) are represented by NCR (Numeric character reference, such as "Chinese characters" will be converted into "Chinese characters"). This kind of coding can be displayed normally in any coding environment.
Add the following three lines to the header of the PHP file:
Mb_internal_encoding ("gb2312"); / / the gb2312 here is the original mb_http_output of your website ("HTML-ENTITIES"); ob_start ('mb_output_handler')
To use the mb_convert_encoding function, you need to enable PHP's mbstring (multi-byte string) extension.
If there is no mbstring extension that does not have PHP enabled, you need to make the following settings for PHP to support the extension.
1. Windows server environment
Edit the PHP.ini file to remove and restart the web server in front of extension=PHP_mbstring.dll.
2. Linux server environment
Add the-- enable-mbstring=cn compilation parameter when compiling the configuration, and then compile and install PHP.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.