In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to solve the error report of iconv function in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Method: 1, add "/ / IGNORE" after the second parameter of the function, the syntax is "iconv (" UTF-8 "," GB2312//IGNORE ",.)"; 2, replace gb2312 with "utf-8", and the syntax is "iconv (" GB2312 "," UTF-8 ",.)".
This article operating environment: Windows10 system, PHP7.1 version, Dell G3 computer
What about the error report of iconv function in php?
Introduction to iconv ()
The iconv function converts one known character set file into another known character set file. For example: convert from GB2312 to UTF-8.
The iconv function is built into php5, and the GB character set is turned on by default.
Iconv () error
Iconv will make an error when converting the character "-" to gb2312. The solution is to add "/ / IGNORE" after the encoding to be converted, that is, after the second argument of the iconv function. As follows:
Iconv ("UTF-8", "GB2312//IGNORE", $data)
Ignore means to ignore the conversion error, and without the ignore parameter, all strings following that character cannot be saved.
In php, iconv function library can complete the conversion between various character sets, which is an indispensable basic function library in php programming; but sometimes iconv transcodes part of the data for no reason. For example, there will be an error when converting the character "- or traditional" to gb2312.
Let's take a look at the usage of this function.
For the simplest application, replace gb2312 with utf-8:
`$ text`` = iconv (``"GB2312"``, ``"UTF-8 "``, ``$ text``); `
In the process of using $text=iconv ("UTF-8", "GB2312", $text), if you encounter some special characters, such as "- or traditional", "." in the English name. Wait for the character, the conversion will be broken. The text after these characters can no longer be converted.
To solve this problem, you can use the following code:
`$ text`` = iconv (``"UTF-8"``, ``"GBK "``, ``$ text``); `
You read it correctly. It's as simple as that. Instead of using gb2312, you can write it as GBK.
In another way, the second parameter, plus / / IGNORE, ignores the error, as follows:
`iconv (``"UTF-8"``, ``"GB2312//IGNORE "``, ``$ data``); `
There is no specific comparison between the two methods, so the first method (GBK instead of gb2312) feels better.
Examples are as follows:
This is the end of the content of "how to solve the error report of iconv function in php". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.