PHP uses AJAX to obtain web pages and output implementation code (Zjmainstay)_PHP tutorial

WBOY
Release: 2016-07-21 15:16:19
Original
1331 people have browsed it

Highlights:
1. file_get_contents timeout control.
2. Page encoding judgment.
3. Enter key on the keyboard to capture the response.
4. Keyboard event compatible processing. //event = event || window.event;
5. XMLHttpRequest and jQuery two implementation solutions.
6. The page and source code are displayed at the same time.
XMLHttpRequest version get_web.php

Copy code 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











}
//End_php

jQuery 版本 get_web.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 {
?>



Get Web Page









站点


站点源码




}
//End_php

作者:Zjmainstay

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325901.htmlTechArticle看点: 1、file_get_contents超时控制。 2、页面编码判断。 3、键盘Enter键捕捉响应。 4、键盘event兼容处理。//event = event || window.event; 5、XMLHttp...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!