PHP uses AJAX to obtain the webpage and output the implementation code (Zjmainstay ). Aspect: 1. file_get_contents timeout control. 2. page encoding judgment. 3. press Enter to capture the response. 4. handle keyboard event compatibility. Eventevent | window. event; 5. XMLHttp aspect:
1. file_get_contents timeout control.
2. page encoding judgment.
3. press Enter to capture the response.
4. handle keyboard event compatibility. // Event = event | window. event;
5. XMLHttpRequest and jQuery implementation solutions.
6. the page and source code are displayed at the same time.
XMLHttpRequest version get_web.php
The code is as follows:
Header ("Content-type: text/html; charset = utf-8 ");
If (! Empty ($ _ POST ['input _ text']) {
Ini_set ('default _ socket_timeout ', 10 );
If (! $ Data = file_get_contents ($ _ POST ['input _ text']) {
Echo "Time out! ";
Return;
}
$ Charset_pos = stripos ($ data, 'charset ');
If ($ charset_pos ){
If (stripos ($ data, 'utf-8', $ charset_pos )){
Echo iconv ('utf-8', 'utf-8', $ data );
} Else if (stripos ($ data, 'gb2312', $ charset_pos )){
Echo iconv ('gb2312', 'utf-8', $ data );
} Else if (stripos ($ data, 'gbk', $ charset_pos )){
Echo iconv ('gbk', 'utf-8', $ data );
}
Return;
}
Echo $ data;
} Else {
?>
Get Web Page