Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert phpinfo string types
How to convert phpinfo string types
The character encoding conversion of iconv and mb_convert_encoding functions in php is described in detail as follows:

Iconv library can complete the conversion between various character sets and is an indispensable basic function library in php programming.

Usage is as follows:

$string? =? "Dear friends, welcome to visit the blog, hoping to bring you some help!" ;

Iconv("utf8 ","gbk ",$string)// String string? Encoding changed from utf8 to gbk;; Expand as follows:

Echo? [mathematics? Processing? Error]str=' Well, welcome to the blog, which records the growth process of a programmer! ′; echo ' & lt; br/>; ′; echoiconv(′GB 23 12′,′UTF? 8′,str); ? //Convert the encoding of the string from GB23 12 to UTF-8.

Echo? & ltbr? />; ”;

Echo? Iconv_substr ([Mathematics? Processing? Error ]str, 1, 1, 'UTF? 8′); //intercept printr (icongetencoding ()) by the number of characters instead of bytes; //Get the current page coding information echiconvstrlen(str, UTF-8'); ? //Gets the set encoding string length.

//is also used in this way.

[mathematics? Processing? Error]content=iconv("UTF? 8 ","gbk//TRANSLIT ",content); Remarks:

1 and iconv are not default functions of php, but also modules installed by default. You need to install it to use it.

If it is windows2000+php, you can modify the php.ini file and put ";" Before extension=php_iconv.dll, delete it, and at the same time, you should copy the iconv.dll under your original php installation file to your winnt/system32 (if your dll points to this directory, I didn't do this locally).

In linux environment, it is enough to add one more item with -iconv during static installation configuration, and phpinfo can see iconv's item. (Linux 7.3+Apache 4.06+PHP 4 . 3 . 2);

This php's introduction to iconv ends here.

2. Convert the captured utf-8 encoded page into gb23 12 with iconv function. It is found that only by transcoding the captured data with iconv function will there be less data for no reason. The reason is this:

String iconv (string input character set, string output character set, string string)

Note: In addition to specifying the code to be converted, the second parameter can also add two suffixes: //translate and //IGNORE, where //translate will automatically turn the characters that cannot be directly converted into one or more approximate characters, //IGNORE will ignore the characters that cannot be converted, and the default effect is to truncate from the first illegal character. If it is truncated, of course, it will be less;

Can Iconv ("UTF-8 ","GB 23 12// ignore ",$ string) be modified in this way? Characters that cannot be converted will be ignored;

Additional:

Introduction of mb_convert_encoding and iconv functions in PHP

The mb_convert_encoding function is used to convert encoding, similar to the iconv function.

There is generally no coding problem in English, but only Chinese data. For example, when writing programs with Zend Studio or Editplus, gbk code is used. If data needs to be entered into the database, and the database coding is utf8, then the data must be coded and converted, otherwise it will become garbled when entering the database.

Highway GBK to UTF 8.

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

Header ("Content type:? Text/html; ? charset = Utf-8 "); ? //Set the encoding of characters to utp-8.

Echo? Mb_convert_encoding ("You are my friend", "UTF 8",? 《GBK》);

& gt do GB23 12 to Big5 again.

& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)

Header ("Content type:? Text/html; ? charset = big 5 ");

Echo? Mb_convert_encoding ("friend ",“big5”,? 《GB 23 12》);

& gt However, to use the above functions, you need to install but first enable the mbstring extension library. The reason is still the same. Modify php.ini

Another function in PHP, iconv, is also used to convert string encoding, similar to the previous function.

Here are some detailed examples:

iconv? —? Convert? String? Where to? Requirements? Character? encode

(PHP? 4? & gt=? 4.0.5,? PHP? 5)

mb_convert_encoding? —? Convert? Character? encode

(PHP? 4? & gt=? 4.0.6,? PHP? 5) Usage:

String? mb_convert_encoding? (? String? str,? String? To _ code? [,? Mixed? From_encoding] You need to enable the mbstring extension library first and put it in php.ini; extension = extension = PHP _ mbstring . dll; ?

Removing mb_convert_encoding can specify a variety of input codes, which will be automatically recognized according to the content, but the execution efficiency is much worse than iconv;

Then why explain this mb_convert_encoding () function? The answer is as follows:

It is found that iconv will make an error when converting the character "-"into gb23 12. If there is no ignore parameter, all strings after this character cannot be saved. In any case, this "-"can't be converted successfully and can't be output.

In addition, mb_convert_encoding does not have this bug.

In general, iconv is used, and mb_convert_encoding function is only used when you are not sure what the original encoding is, or iconv cannot be displayed normally after conversion.