如果我正確理解你的話,它看起來像你想從otherdomain.com獲取搜索結果,並在你的網站上顯示結果,而不是將用戶重定向到otherdomain.com。這是對的嗎?
如果是這樣你想看到的是通過PHP的屏幕抓取,有幾個技巧(捲曲&正則表達式)可以使用,這是一個非常簡單的例子,我剛剛用谷歌作爲例子。
創建一個名爲search.php的文件並將此代碼放入它中 - 應該直接從蝙蝠上完成。
<h1> Super Search Site </h1>
<form action="search.php" method="post">
Search: <input type="text" name="search" />
<input type="submit" />
</form>
<?php
@$searchString = $_REQUEST["search"];
if(isset($searchString))
{
$pageRaw = file_get_contents("http://www.google.co.uk/search?q=$searchString");
$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); //removes all white space - inclding tabs, newlines etc - makes easier when using regex
$pageCleaned = str_replace($newlines, "", html_entity_decode($pageRaw));
/*
* $contentStart = the start of content wanted
* $contentEnd = the end of content wanted
* $contentWanted = content between $contentStart and $contentWanted
*/
$contentStart = strpos($pageCleaned,'<ol>'); //Looks in the source code for <ol>
$contentEnd = strpos($pageCleaned,'</ol>',$contentStart); //Looks in the source code for </ol>
$contentWanted = substr($pageCleaned,$contentStart,$contentEnd-$contentStart);
echo $contentWanted;
}
else
{ return; }
?>
我想要這樣的確切的事情,但是,搜索引擎只需要post元素..即,它不會採取查詢字符串:)其我的錯誤,我沒有提到它的問題...任何方式這是偉大的,非常感謝你,我會在我的其他項目中使用這種技術 – diamond
此鏈接應該幫助你:) [通過curl發送HTTP POST](http://davidwalsh.name/execute-http-post-php -捲曲) – TheNovadex