File_get_contents collects data from a page, gets the data is garbled, has used the method of detection encoding,
Detection is utf-8, my page encoding is also utf-8, but still show garbled, do not know why
$url = "xxx"; $opts = Array (' http ' =>array (' user_agent ' = = "mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) ", )); $context = Stream_context_create ($opts); $neirong = File_get_contents ($url, False, $context); Header ("content-type:text/html; Charset=utf-8 "); Ob_end_flush (); $encode = mb_detect_encoding ($neirong, Array ("ASCII", "UTF-8", "GB2312", "GBK", "BIG5")); echo $encode. "
"if ($encode! =" UTF-8 ") { $neirong =mb_convert_encoding ($neirong," UTF-8 ", $encode); } Echo $neirong;
$encode Output: Utf-8
$neirong output is garbled
My page encoding is Utf-8
Reply to discussion (solution)
... $neirong = file_get_contents ($url, False, $context); Echo Base64_encode ($neirong);
Post the results
... $neirong = file_get_contents ($url, False, $context); Echo Base64_encode ($neirong);
Post the results
is an article, the result is too long, I put a piece of it
77u/icagioiwjeewloahteayloazhoixkeebqoaak++8jomaves6juwhkes+k+wyqeegmueeg+ebqoa0headremav
$c = ' 77u/icagioiwjeewloahteayloazhoixkeebqoaak++8jomaves6juwhkes+k+wyqeegmueeg+ebqoa0headremav '; Echo base64_ Decode ($c);
The spy boils????, the???? of the rock. Hang??
??? Ah. The last one? Your base64 is incomplete.
$c = ' 77u/icagioiwjeewloahteayloazhoixkeebqoaak++8jomaves6juwhkes+k+wyqeegmueeg+ebqoa0headremav '; Echo base64_ Decode ($c);
The spy boils????, the???? of the rock. Hang??
??? Ah. The last one? Your base64 is incomplete.
The correct output should be "Let Tanaka, the six-job actually does not mean this aspect." ”
It's garbled.
The address of the set?
The address of the set?
This is the data acquisition address.
Http://www.ziyouge.com/conbdhekbefiab
This is the display page of its website
Http://www.ziyouge.com/zy/4/4980/1333249.html
The data collected from the address is not normal, but its page is displayed correctly
Need?? Set of?? Do something.
=224) {$result. = Change (Mb_substr ($content, $i, 3)); $i = $i +3;} else{$result. = Mb_substr ($content, $i, 1); $i = $i +1;}} echo $result;//function Change ($str) {$ignore = Array (' "', '" ', '! ', ' ... ', ': ', ', ', ', '); if (In_array ($str, $ignore)) {return $str;} $prefix = "%u"; $postfix = ""; $str = Iconv (' UTF-8 ', ' UCS-2 ', $str); $arrstr = Str_split ($str, 2); $unistr = "; for ($i = 0, $len = count ($arrstr), $i < $len, $i + +) {$tmp = Hexdec (Bin2Hex ($arrstr [$i])); $tmp = Str_pad (Dechex ( $TMP), 4, ' 0 ', str_pad_left); $tmp = Decrypt (substr ($tmp, 2,2). substr ($tmp, 0,2)); $unistr. = $prefix. $tmp. $postfix; }return unescape ($UNISTR);} Decrypt function Decrypt ($d) {$result. = Str_pad (Dechex (Hexdec ($d) -100), 4, ' 0 ', str_pad_left); return $result;} ? Chinese function unescape ($str) {$ret = '; $len = strlen ($STR); for ($i = 0; $i < $len; $i + +) {if ($str [$i] = = '% ' && $str [$i + 1] = = ' U ') {$val = he Xdec (substr ($str, $i + 2, 4)); if ($val < 0x7f) $ret. = Chr ($val); else if ($val < 0x800) $ret. = Chr (0xc0 | ($val >> 6)) . Chr (0x80 | ($val & 0x3f)); else $ret. = Chr (0xe0 | ($val >> 12)) . Chr (0x80 | (($val >> 6) & 0x3f)) . Chr (0x80 | ($val & 0x3f)); $i + = 5; } else if ($str [$i] = = '% ') {$ret. = UrlDecode (substr ($str, $i, 3)); $i + = 2; } else $ret. = $str [$i]; } return $ret; }?>
It is already 11 o'clock in the evening, the roadside partner basic? What person, but still have three goods still drink of elation, and do not go to the dawn, no longer to the meaning,
Fdipzone, with your method or output garbled, not very understanding of decryption
You add in the HTML out of the
It source?? Did you do something about it? , my program has been? It's????. The
I'm going to go straight to the right place.
$v) {$HEADERARR [] = $n. ': '. $v; } $ch = Curl_init (); curl_setopt ($ch, Curlopt_returntransfer, True), curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ CH, curlopt_httpheader, $HEADERARR); Tectonic ipcurl_setopt ($ch, Curlopt_referer, ' http://www.ziyouge.com/'); Construct the route $content = curl_exec ($ch); $content = substr ($content, 3); if ($error =curl_error ($ch)) {die ($error);} Curl_close ($ch);//analysis program $result = '; $str _length = Mb_strlen ($content); $i =0;while ($i <= $str _length) {$temp _str=mb_ substr ($content, $i, 1), $ascnum =ord ($temp _str), if ($ascnum >=224) {$result. = Change (Mb_substr ($content, $i, 3)); $i = $i +3;} else{$result. = Mb_substr ($content, $i, 1); $i = $i +1;}} Echo '
'; echo $result;//function Change ($str) {$ignore = Array (' "', '" ', '! ', ' ... ', ': ', ', ', ', '); if (In_array ($str, $ignore)) {return $str;} $prefix = "%u"; $postfix = ""; $str = Iconv (' UTF-8 ', ' UCS-2 ', $str); $arrstr = Str_split ($str, 2); $unistr = "; for ($i = 0, $len = count ($arrstr), $i < $len, $i + +) {$tmp = Hexdec (Bin2Hex ($arrstr [$i])); $tmp = Str_pad (Dechex ( $TMP), 4, ' 0 ', str_pad_left); $tmp = Decrypt (substr ($tmp, 2,2). substr ($tmp, 0,2)); $unistr. = $prefix. $tmp. $postfix; }return unescape ($UNISTR);} Decrypt function Decrypt ($d) {$result = Str_pad (Dechex (Hexdec ($d) -100), 4, ' 0 ', str_pad_left); return $result;} ? Chinese function unescape ($str) {$ret = '; $len = strlen ($STR); for ($i = 0; $i < $len; $i + +) {if ($str [$i] = = '% ' && $str [$i + 1] = = ' U ') {$val = he Xdec (substr ($str, $i + 2, 4)); if ($val < 0x7f) $ret. = Chr ($val); else if ($val < 0x800) $ret. = ChR (0xc0 | ($val >> 6)) . Chr (0x80 | ($val & 0x3f)); else $ret. = Chr (0xe0 | ($val >> 12)) . Chr (0x80 | (($val >> 6) & 0x3f)) . Chr (0x80 | ($val & 0x3f)); $i + = 5; } else if ($str [$i] = = '% ') {$ret. = UrlDecode (substr ($str, $i, 3)); $i + = 2; } else $ret. = $str [$i]; } return $ret; }?>
You add in the HTML out of the
It source?? Did you do something about it? , my program has been? It's????. The
I'm going to go straight to the right place.
[/code]
Garbled is because PHP version is different, I 5.3.28 test normal, in PHP 6.0.0-dev test is garbled, is not PHP 6.0.0-dev missing what components
It's possible, Dev edition.
It's possible, Dev edition.
Local 5.3.28 Normal, change to server 5.3.28 again garbled ...
Liunx environment, the local Ubuntu, the server is Debian
Assessment?? What is the version of PHP MB string?.
The boundary?? You can only rely on yourself, I??? Yes?? More.
Assessment?? What is the version of PHP MB string?.
The boundary?? You can only rely on yourself, I??? Yes?? More.
have found the problem. Under different platforms
$str = Iconv (' UTF-8 ', ' UCS-2 ', $str); The output of this sentence is different.
For example: $str = "?"; $str = Iconv (' UTF-8 ', ' UCS-2 ', $str); The normal result is "v^"; the abnormal result is "^v"; ask this How to solve
Find a way. Different usc-2 encoding for different platform conversions
For UCS-2, the default is Ucs-2be under Linux. Use Iconv (Specify UCS-2) to convert the generated Unicode to UCS-2BE. If you convert the Windows platform over the UCS-2, you need to specify Ucs-2le.
Well
$str = Iconv (' UTF-8 ', ' UCS-2 ', $str);
Change?
$str = Iconv (' UTF-8 ', ' Ucs-2le ', $str);
You can do it.