04 January 2010

get searching data from google on localhost

Hi friends,
Try this to get search data on your local host.

$text = $_POST['search'];


<form action="searchbygoogle.php" method="POST">
<input name="search" type="text" value="<?= $text;?>" />
<input type="submit" value="Search" />

if ($_POST['search']==""){
echo "No search data found";
$query = file_get_contents("http://www.google.com/search?q=".urlencode($_POST['search'])."&hl=en&ie=UTF-8&filter=2");

//needs to be added with more queries
$replace_array = array('/\n/','/(.*)<\/head>/','/(.*)
//pregraplacing unneeded parts
$results = preg_replace($replace_array, '', $query);
echo $results;


No comments:

Post a Comment