ignore characters that cannot be converted and avoid errors but cannot output them correctly (that is, blank spaces and outputs ).
Next let's take a look at the php Tutorial iconv (): detected an illegal character in input string processing method:
$str = iconv('utf-8', 'gbk//ignore', unescape(isset($_get['str'])? $_get['str']:''));
In the local test, // ignore can ignore the words it does not know and then turn them down without an error. // Transcoder
The Code is as follows:
Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload/". $ _ FILES ["file"] ["name"]);
Change
The Code is as follows:
Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload /". iconv ("UTF-8", "gbk", $ _ FILES ["file"] ["name"]);
The returned value of the iconv function is false.
Check the function manual and find that the second parameter has a special usage. A simple translation is that I can append // Transcoder
Garbled characters often occur in Chinese writing, and Encoder translation is stuck, and some cannot be translated. Use translation functions:
Gb2312 to UTF-8
$ UTF = iconv ('gb2312', 'utf-8', $ _ request ['keyword']);
Convert string UTF-8 to gb2312
$ STR = iconv ("UTF-8", "gb2312 // Transcoder", $ Str );
PHP Code Conversion Function
The iconv () function definition and usage defines and uses the iconv (
Php learning path: iconv function description in php iconv function library can complete conversion between various character sets. it is an indispensable basic function library in php programming.
The usage is as follows:
$ String = "dear friend, welcome to Hu Wenfang's blog and hope to help you a little bit! ";
Iconv ("utf8", "gbk", $ string) // Convert string encoding from utf8 to gbk;
The extension is as follows:
Echo $ str = 'hi! welcome to Hu Wenfang's blog, which records the growth
transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string //IGNORE, characters that cannot be represented in the target charset are silently discarded. Otherwise, str is cut from the first illegal character.
When using this function for string encoding conversion, note that if UTF-8 is converted to gb2312, the string may be truncated. You can solv
following string to see the effect.
$ Str = "www.blogguy.cn, OK! The string is €. I want to convert it! ⊙ ●○ ① {◎ {⊙ ";Echo 'has no parameters:', iconv ("UTF-8", "gbk", $ str )."";
The result returned on my computer isOneAny character after a special character cannot be displayed.
Iconv has two parameters: Transcoder and IGNORE, respectively. Transcoder indicates that if the original encoding cannot be tra
provider and converter to the configuration through the factory mode. In this way, configuration writes a general abstract factory configurationfactory, which is used to obtain the context of configuration and createinstance (string configurationname), a configuration class of the configuration name. In this method, it works on Createobject (). (Note: Both the storage provider and The Transcoder are the configurator, which is somewhat far-fetched.) N
. add "// ignore" after the output character encoding string, such as iconv ('utf-8', 'gb2312 // ignore ', 'www. bKjia. c0m'). In this way, you can ignore characters that cannot be converted and avoid errors but cannot output them correctly (that is, blank spaces and outputs ).
Next let's take a look at the php Tutorial iconv (): detected an illegal character in input string processing method.
$ Str = iconv ('utf-8', 'gbk // ignore ', unescape (isset ($ _ get ['str'])? $ _ Get ['str']: '');In th
unchanged. at the same time, some webpages may contain special symbols, encoding conversion causes loss. some webpages only get one segment.
Ask for solutions ......
------ Solution --------------------
Some iconv () functions cannot be converted. you can use the mb_convert_encoding () function to convert the code.
------ Solution --------------------
The second solution is better. after iconv conversion, the webpage content is normal and will not be garbled.
Iconv ("GB2312", "UTF-8 //
/". $ _ FILES ["file"] ["name"]);To:Move_uploaded_file ($ _ FILES ["file"] ["tmp_name"], "upload /". iconv ("UTF-8", "gbk", $ _ FILES ["file"] ["name"]);The returned value of the iconv function is false. Check the function manual and find that the second parameter has a special usage. a simple translation is that I can append // Transcoder or // IGNORE after the encoding, the former converts untranslated characters into the nearest character, while th
tool/MAC motion picture maker/The most powerful GIF maker in historyOS X screencast to animated GIF (quicktime+ffmpeg+gifsicle)MOV to GIF online converter:cloudconvert,zamzar,imedia Converter Deluxe
Video Converter
handbrake(Windows/mac os/ubuntu): The Open source video transcoderAVC: Any Video Converter for free (Windows/mac OS)Video Converter Ultimate(Windows/mac OS)Apowersoft Video Converter: Mac os/windows/studioAdapter: Adapter con
: // transcoder and // IGNORE, // Transcoder automatically converts a character that cannot be directly converted into one or more similar characters. // IGNORE ignores the characters that cannot be converted, by default, the result is truncated from the first invalid character.
Returns the converted string or FALSE on failure.
Usage:It is found that iconv will encounter an error when converting characters
above functions, you need to install but enable mbstring Extension Library first.
Another function iconv in PHP is also used to convert string encoding, similar to the function above.
The following are examples:
The code is as follows:
Iconv-Convert string to requested character encoding
(PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding
(PHP 4> = 4.0.6, PHP 5)
Usage:String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable mbstring exten
also used to convert string encoding, similar to the function above.
The following are examples:
Iconv-Convert string to requested character encoding
(PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding
(PHP 4> = 4.0.6, PHP 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable mbstring extension Library first, and remove the extension library before extension = php_mbstring.dll in php. ini.
Mb_convert_encoding can specify multip
enable mbstring Extension Library first.
Another function iconv in PHP is also used to convert string encoding, similar to the function above.
The following are examples:
Iconv-Convert string to requested character encoding
(PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding
(PHP 4> = 4.0.6, PHP 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable mbstring extension Library first, and remove the extension library before exten
Description of the differences between iconv and mb_convert_encoding in php conversion strings. For more information, see. Iconv-Convert string to requested character encoding (PHP 4> = 4.0.5, PHP 5)
Mb_convert_encoding-Convert character encoding (PHP 4> = 4.0.6, PHP 5)
Usage:
String mb_convert_encoding (string str, string to_encoding [, mixed from_encoding])
Enable the mbstring extension Library first. in php. ini, remove the extension before php_mbstring.dll.
String iconv (string in_charset
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.