저는 검색 엔진을 만들고 있습니다. 기능 중 하나는 Google을 검색하는 것입니다. 내가 한 첫 번째 작업은 URL만으로 Google 검색을 생성하는 방법을 찾는 것입니다. "http://www.google.com/search?hl=en & source = hp & biw = 1542 & bih = 928 & q ="첫 번째 부분이고 "Query"는 두 번째 부분이며 "& 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>";
?>
감사합니다. 난 당신이 PHP는 매우 새로운이고 어딘가에 맞게 수정 시도에서이 스크립트를 입수했습니다 있으리라 믿고있어
<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
"으로 지정했습니다. 그러나 클라이언트 측에서 그럴듯하게 만들려고 시도한 것은 완전히 실패했습니다 "- 어떻게? 왜? –
으악, 나는 서버 측을 의미했다. 방금 고정했습니다 – Matthew