. ini.
C. Restart Apache and check whether iconv is enabled in phpinfo.Recently, I am working on a program. I need to use the iconv function to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data into less data for no reason. I was depressed for a while. I checked the information on the Internet to find out that this is a bug in the iconv function. Iconv will encounter an error when converting the character "-" To g
Solution to phputf-8 conversion gb2312 string truncated. Iconv (UTF-8, gb2312ignore, $ data) ignore directly means to ignore the conversion error. if the ignore parameter is not specified, all strings after this character cannot be iconv ("UTF-8", "gb2312 // ignore", $ data)
Ignore directly means ignore. in this case, the conversion error is ignored. without the ignore parameter, all strings after this character cannot be saved.
Conv is not the default function in the php Tutorial, but also the
Iconv encoding conversion in php solves Chinese garbled characters. Use the iconv function to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data to code data without any reason. some code is as follows: The iconv function is used to convert the captured UTF-8 encoded page to gb2312, it is found that only the iconv function can be used to convert the captured data into less data for no reason.
The code is
.
The iconv method is used for encoding conversion.
Iconv-string conversion based on the required character encodingString iconv (string $ in_charset, string $ out_charset, string $ str)
Encodes str from in_charset to out_charset.
The conversion method is simple. you can simply use the iconv method.
?
1 2 3
$ Content = iconv ('gb2312', 'utf-8', $ content); // $ content indicates the collected content. ?>
After testing several pages, the data can be coll
How can I determine whether a web page is viewed on a pc or a mobile phone? How can I determine whether a web page is viewed on a pc or a mobile phone?
Reply content:
How can I determine whether a web page is viewed on a pc or a mobile phone?
PHPA library for mobile phone detection is very famous.Mobile-DetectAddress: https://packagist.org/packages/mobiledetect/mobiledetectlib
0?$matches[0]:''; function CheckSubstrs($substrs,$text){ foreach($substrs as $substr){ i
.
After testing several pages, the data can be collected normally. However, in subsequent collection, the collection of several pages is incomplete.Check the backend servers for regular expressions. After investigation, it is found that the content after iconv transcoding is much less than the collected content.View the apache log and see the prompt: Notice: iconv (): Detected an illegal character in input string.
Refer to the manual and see the following description.
If you add a string //
following settings $ str = mb_convert_encoding ($ str, "UTF-8 ", "GBK"); then you can. Of course you can also use iconv (); make the following settings iconv ('gbk', "UTF-8 // Transcoder // IGNORE", $ str ); these two functions solve the problem of garbled code on windows.
Problem 2:
Php reads csv files, and Chinese characters cannot be read in linux. baidu and google find a solution.
You just added a line of code setlocale (LC_ALL, 'zh _ cn'). Ye
How to determine whether to use PC-side or mobile-browsing Web page?
Reply content:
How to determine whether to use PC-side or mobile-browsing Web page?
PHPThere's a library of cell phone tests.Mobile-DetectAddress: Https://packagist.org/packages/mobiledetect/mobiledetectlib
0. $matches [0]: "; function Checksubstrs ($substrs, $text) {foreach ($substrs as $substr) {if (False!==strpos ($text, $substr)) { return true; }else{return false; }}} $mobile
The iconv function is used to convert the captured UTF-8 encoded page into gb2312. it is found that only the iconv function can be used to convert the captured data into less data for no reason.
The iconv function is used to convert the captured UTF-8 encoded page to gb2312, and it is found that only the iconv function can be used to convert the captured data to less data for no reason. the code is as follows:
Echo $ str = 'Hi, it's coffee sale! ';
Echo'
';
Echo iconv ('gb2312
ignore parameter, all strings after this character cannot be saved.
This iconv () function is built-in in php5. thank you.
Column
Echo $ str = 'Hi, it's coffee sale! ';Echo'';
Echo iconv ('gb2312', 'utf-8', $ str); // Encode the string from GB2312 to UTF-8Echo'';
Echo iconv_substr ($ str, 1, 1, 'utf-8'); // truncate by number of characters rather than bytesPrint_r (iconv_get_encoding (); // Obtain the encoding information of the current page.
Echo iconv_strlen ($ str, 'utf-8'); // you can spe
Phpiconv function usage example and precautions
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
this method, so find out if there are any functions in PHP that can meet my needs.
At this time, I thought of the iconv () function used to process file names in windows. its function prototype is as follows:
string iconv ( string $in_charset , string $out_charset , string $str )Performs a character set conversion on the string str from in_charset to out_charset.
We often use:
$out_charset='utf-8';$fileName=iconv($fileName,$out_charset,'gbk');
To process the file name, change the file name
Notes for using iconv in php. Stringiconv (string $ in_charset, string $ out_charset, string $ str) when using this function for string encoding conversion, note that if UTF-8 is converted to gb2312
String iconv (string $ in_charset, string $ out_charset, string $ str)
When using this function for string encoding conversion, note that if UTF-8 is converted to gb2312, the string may be truncated.
You can solve this problem by using the following methods:
The code is as follows:
// Autho
.
After testing several pages, the data can be collected normally. However, in subsequent collection, the collection of several pages is incomplete.Check the backend servers for regular expressions. After investigation, it is found that the content after iconv transcoding is much less than the collected content.View the apache log and see the prompt: Notice: iconv (): Detected an illegal character in input string.
Refer to the manual and see the following description.
If you add a string //
Access to websites through mobile phones is becoming more and more popular. if we want to count the traffic of websites through PCs and mobile terminals, or we need to do some special processing for mobile terminals, then we need to identify the client of the user accessing the website. The following example uses php to identify whether the user accesses the website through a computer or a mobile phone. Lt ;? PhpfunctionisMobile () {$ useragentisset, or if you need to do some special processing
If the output encoding format does not contain any character, you can search for the replacement character in the similar encoding; 'ignore': If the output encoding format does not contain a character in the string, it can skip encoding of subsequent characters. Otherwise, output will be interrupted when transcoding fails and an error will be generated.
1. view the input, internal, and output code on the page:
Print_r (iconv_get_encoding ("all "));
2. encode and convert the specified string:
Ech
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.