您好,欢迎访问一九零五行业门户网

PHP 利用AJAX获取网页并输出(原创自Zjmainstay)

看点: 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;
      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 {?> span>public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> get web pageclass=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 {?> span>public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd> get web pageclass=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>站点源码
class=hide_box>php } //end_php
其它类似信息

推荐信息