- Echo $ str = 'Hi, it's coffee sale! ';
- Echo'
';
- Echo iconv ('gb2312', 'utf-8', $ str); // Encode the string from GB2312 to UTF-8
- Echo'
';
- Echo iconv_substr ($ str, 1, 1, 'utf-8'); // truncate by number of characters rather than bytes
- Print_r (iconv_get_encoding (); // Obtain the encoding information of the current page.
- Echo iconv_strlen ($ str, 'utf-8'); // you can specify the length of the encoded string.
- // There is also a bbs.it-home.org for this use
- $ Content = iconv ("UTF-8", "gbk // transcoder", $ content );
- ?>
Notes for using iconv functions in php
When iconv () is used to convert a character that is not supported by the output character encoding, such as iconv ('utf-8', 'gb2312 ', 'hangzhou'), the following error occurs: notice: iconv () [function. iconv]: Detected an illegal character in input string... because GB2312 represents simplified Chinese, it does not support more complex Chinese characters such as "simplified" and some special characters. of course, an error is returned.
There are two solutions: 1. expand the output character encoding range, such as iconv ('utf-8', 'gbk', 'authorization, because GBK supports a wider range of characters, 2. add "// IGNORE" after the output character encoding string, such as iconv ('utf-8', 'gb2312 // IGNORE ', 'unconvertible characters are ignored to avoid errors but cannot be correctly output (that is, no blank space or output ). |