我正在制作搜索引擎,其中一项功能是搜索Google等功能。我做的第一件事就是了解如何仅基于URL生成Google搜索。那么,“http://www.google.com/search?hl=zh-CN & source = hp & biw = 1542 & bih = 928 & q =”是第一部分,“查询”是第二部分,而“& aq = f & aqi = g10 & aql = & oq = & qscrl = 1“是第三部分。现在,在客户端,我制作了一个名为“搜索”的表单,其操作是下面的文件。但是,我在服务器端做出这种似是而非的尝试完全失败了。以下是代码:呼应变量
<?php
$something = $_REQUEST["search"];
$txt1="http://www.google.com/search?hl=en&source=hp&biw=1542&bih=928&q=";
$txt2 = $something;
$txt3="&aq=f&aqi=g10&aql=&oq=&qscrl=1";
$string=$txt1.$txt2."+".$txt3;
$link_to_dig = $string;
$original_file = @file_get_contents($link_to_dig);
if(!$original_file)
die("Error loading {$link_to_dig}");
$path_info = parse_url($link_to_dig);
$base = $path_info['scheme'] . "://" . $path_info['host'];
$stripped_file = strip_tags($original_file, "<a>");
$fixed_file = preg_replace("/<a([^>]*)href=\"\//is", "<a$1href=\"{$base}/", $stripped_file);
$fixed_file = preg_replace("/<a([^>]*)href=\"\?/is", "<a$1href=\"{$link_to_dig}/?", $fixed_file);
preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is", $fixed_file, $matches);
//DEBUGGING
//$matches[0] now contains the complete A tags; ex: <a href="link">text</a>
//$matches[1] now contains only the HREFs in the A tags; ex: link
$result = print_r($matches, true);
$result = str_replace("<", "<", $result);
print "<pre>" . $result . "</pre>";
?>
感谢您的帮助!
这是形式:
<form class="searchengine" name="search" action="search.php" method="post">
<input type="text" style="width:580px; height:35px; color:#000000;" class="search" name="search" />
</form>
要指定,当我说“查询”是第二部分时,我的意思是作为一般的“在这里插入查询”类型的东西 – Matthew 2011-04-21 00:00:34
“但是,我试图在客户端做出这种合理的尝试已经完全失败“ - 怎么样?为什么? – 2011-04-21 00:00:51
哎呦,我的意思是服务器端。我只是修复了 – Matthew 2011-04-21 00:01:25