2011-06-19 23 views
0

私は他のドメインであるURLにデータを投稿するフォームを持っています...私はアドレスバーのURLを変更しないで私のドメインでフォームを使用しなければなりません...私はotherdomainの中に結果を示している(これはURL http://otherdomain.com/searchへの投稿データを)http://mydoamin.com/index.html で、今、私はそれを提出する上でクリックすると、検索ボックスを持っている 他のページの結果を必要なページに表示

詳細... ...私は必要

ページhttp://mydoamin.com/search.htmlを作成し、ここに結果を表示してください。

私はこれを行う..(iframe、javascript、jquery、phpを使って)?

答えて

0

私が正しく理解している場合は、otherdomain.comから検索結果を取得し、その結果を他のdomain.comにリダイレクトする代わりにサイトに表示したいと思うようです。それは正しいのでしょうか?

もしあなたが調べたいのがPHPによるスクリーンスクレイピングであれば、使用できる2つのテクニック(Curl & regex)があります。ここでは例としてgoogleを使って作った非常に簡単な例を示します。

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

私はこのような正確なことが欲しいですが、検索エンジンはポスト要素だけを取ります。つまり、クエリ文字列を取ることはありません:)その私の間違いは質問で言及していません... any私は他のプロジェクトでこのテクニックを使用します – diamond

+0

このリンクはあなたを助けます:) [CurlでHTTP POSTを送信する](http://davidwalsh.name/execute-http-post-php -カール) – TheNovadex

関連する問題