Watch:
1, file_get_contents timeout control.
2, page encoding judgment.
3. The keyboard enter key to capture the response.
4, keyboard event compatible processing. Event = Event | | window.event;
5, XMLHttpRequest and jQuery two kinds of realization scheme.
6, the page and source code at the same time display.
XMLHttpRequest version get_web.php
Copy CodeThe 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 {
?>
<title>Get Web Page</title>
Visit the original station
Back off
}
end_php
JQuery version get_web.php
Copy CodeThe 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 {
?>
<title>Get Web Page</title>
Visit the original station
Back off
Site
Site Source
<textarea id="output_page_html" class="hide_box"></textarea>
}
end_php
Author: Zjmainstay
http://www.bkjia.com/PHPjc/325901.html www.bkjia.com true http://www.bkjia.com/PHPjc/325901.html techarticle spectacle: 1, file_get_contents timeout control. 2, page encoding judgment. 3. The keyboard enter key to capture the response. 4, keyboard event compatible processing. Event = Event | | window.event; 5. XMLHttp ...