2011-06-19 88 views
0

我有一個表單將數據發佈到一個其他域的URL ..我必須使用我的域中的表單,不用更改地址欄中的網址... 細節...在所需頁面顯示其他頁面結果

我有一個搜索框(該數據會發布到URL http://otherdomain.com/search)在http://mydoamin.com/index.html 現在,當我點擊提交它顯示在otherdomain結果...

我需要做一頁http://mydoamin.com/search.html並在這裏顯示結果..

怎麼可以我這樣做(使用iframes,JavaScript,jQuery或PHP)?

回答

0

如果我正確理解你的話,它看起來像你想從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; } 

?> 
+0

我想要這樣的確切的事情,但是,搜索引擎只需要post元素..即,它不會採取查詢字符串:)其我的錯誤,我沒有提到它的問題...任何方式這是偉大的,非常感謝你,我會在我的其他項目中使用這種技術 – diamond

+0

此鏈接應該幫助你:) [通過curl發送HTTP POST](http://davidwalsh.name/execute-http-post-php -捲曲) – TheNovadex

相關問題