看点: 1、file_get_contents超时控制。 2、页面编码判断。 3、键盘Enter键捕捉响应。 4、键盘event兼容处理。// event = event || window. event; 5、 XMLHttpRequest 和 jQuery 两种实现方案。 6、页面及源码同时展示。 XMLHttpRequest版本 get_web.php ?
看点:
1、file_get_contents超时控制。
2、页面编码判断。
3、键盘Enter键捕捉响应。
4、键盘event兼容处理。//event = event || window.event;
立即学习“PHP免费学习笔记(深入)”;
5、XMLHttpRequest 和 jQuery 两种实现方案。
6、页面及源码同时展示。

XMLHttpRequest版本 get_web.php
php 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 { ?> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">Get Web Page class="div_box"> class="input_box" type="text" value="" onclick="check_(true)" onblur="check_(false)"> class="button_box" onclick="get_page()" value="Get it!" >class="hide_box"> class="a_box" href="#" target="_black">访问原站 class="a_box" href="#">后退class="clear_box">php } //End_php

jQuery 版本 get_web.php
php 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 { ?> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">Get Web Page class="div_box"> class="input_box" type="text" value=""> class="button_box" value="Get it!" >class="hide_box"> class="a_box" href="#" target="_black">访问原站 class="a_box" href="#">后退class="clear_box">class="html_tips hide_box">站点class="html_tips hide_box">站点源码php } //End_php










