PHP 输出文本框内容到变量 然后抓取内容

一个文本框 一个按钮 在文本框输入内容 点击按钮以后 就把输入的内容串到一串网址中 然后抓取这串网址对应的页面 不用对抓取的内容做任何处理直接在下方显示,能做到么?

第1个回答  2012-02-23
<?php
header("Content-type: text/html; charset=utf-8");
if(!empty($_POST['input_text'])) {
$data = file_get_contents( $_POST['input_text'] );
$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 {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<title>Get Web Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<script type="text/javascript">
function createXMLHTTP()
{
try
{
var request = new XMLHttpRequest();
}
catch(e1)
{
var arrVersions = ["Microsoft.XMLHTTP","MSXML2.XMLHttp.4.0",
"MSXML2.XMLHttp.3.0","MSXML2.XMLHttp.5.0"];
for(var i=0;i < arrVersions.length;i++){
try{
request = new ActiveXObject(arrVersions[i]);
}catch(e2){
request = false;
}
}
}
return request;
}

function ajax_post(url, params, target_id)
{
request = new createXMLHTTP();

request.onreadystatechange = function() {
if (this.readyState == 4)
if (this.status == 200)
if (this.responseText != null)
document.getElementById(target_id).innerHTML = this.responseText;
}

request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("Content-length", params.length);
request.setRequestHeader("Connection", "close");
request.send(params);
}

var checked = false;
function check_(value) {
checked = value;
}

function get_key(event) {
event = event || window.event;
if(event.keyCode==13 && checked != false)
{
var url = document.getElementById('input_text').value;
if(url != '') {
get_page();
}else {
document.getElementById('input_text').onfocus();
return false;
}
}
}

function get_page() {
var url = document.getElementById('input_text').value;
if(!url) {
return false;
}else {
if(document.getElementById('output_page').innerHTML != '') {
document.getElementById('output_page').innerHTML = '';
}
}
if(url.indexOf('http://') == -1) {
url = 'http://'+url;
}
ajax_post(
'get_web.php',
'input_text='+url,
'output_page'
);
document.getElementById('click_show').style.display = 'block';
document.getElementById('back_a').href = document.location.href;
document.getElementById('origin_website').href = url;
}
</script>
<style>
.div_box{
margin-top:10px;
}
.input_box{
border:1px solid;
margin-left:10px;
margin-top:2px;
height:15px;
float:left;
size:32
font-size: 14px;
}
.button_box{
float:left;
height:23px;
padding-bottom:3px;
}
.hide_box{
display:none;
}
.a_box{
margin-left:10px;
margin-top:3px;
height:15px;
float:left;
font-size: 14px;
}
.clear_box{
height:50px;
}
</style>
</head>
<body onkeydown="get_key(event)">
<div class="div_box">
<input id="input_text" class="input_box" type="text" value="" onclick="check_(true)" onblur="check_(false)"></input>
<input type="button" class="button_box" onclick="get_page()" value="Get it!" ></input>
<div id="click_show" class="hide_box">
<a id="origin_website" class="a_box" href="#" target="_black">访问原站</a>
<a id="back_a" class="a_box" href="#">后退</a>
</div>
</div>
<div class="clear_box"></div>
<div id="output_page"></div>
</body>
</html>
<?php
}
//End_php本回答被网友采纳
第2个回答  推荐于2016-09-10
  <?php

  $wd = $_GET['wd']; // 获取页面提交来的GET参数
  $content = fetch_get_contents(" ".$wd); // 根据提交来的GET参数采集百度相关页面
  echo $content; // 输出
  ?>
  最简单的版本,form表单用get来提交,文本框name值是wd,可以自己改
第3个回答  2012-02-20
说得偶不是很明白,能实施清楚点吗?

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网