Jump to content

Recommended Posts

If I was doing it I'd do something like this:

 

<?php

$links = array("http://www.google.co.uk/search?q={QUERY}", "http://search.live.com/results.aspx?q={QUERY}");

$query = $_GET['query']; // Contains the value of what you want to search for

foreach($links as $url) {
$url = str_replace("{QUERY}", $query, $url);
$content = file_get_contents($url);
echo "$content\n\n";
}

?>

 

You'd then go on to parse $content reading the bits of data you want.

 

:)

Well at the moment that code takes the query (what you want to search for) and searches for it in each search engine found in the $links array.

 

In the $links array, you need to insert all the search engine urls, placing {QUERY} where the search query goes. I worked out the links for Google and Live already. So you may do this:

 

index.php:

<form action="search.php" method="post">Search for: <input type="text" name="query" /></form>

 

and alter the PHP code to:

 

search.php:

<?php

$links = array("http://www.google.co.uk/search?q={QUERY}", "http://search.live.com/results.aspx?q={QUERY}");

$query = $_POST['query']; // Contains the value of what you want to search for

foreach($links as $url) {
$url = str_replace("{QUERY}", $query, $url);
$content = file_get_contents($url);
echo "$content\n\n";
}

?>

Well now you have the variable, $content, containing the source code of the result page of each search engine. Now you need to start parsing the HTML output of the page to fish out the bits of info you want.

 

Also, instead of going to http://www.designervision.co.nz/search/search.php, go to http://www.designervision.co.nz/search/index.php and type in your query and hit the return key. :)

 

Look up HTML parsing and see what you can find!

If I were doing it I'd start with Live search because its results are easier to parse. I don't want to tell you all the code because it doesn't help you learn at all. This function is useful:

 

<?php


function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
$pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
if($pos2!==false){
  $myarray[]=substr($s,$pos1+$L1,$pos2);
  $s=substr($s,$pos1+$L1+$pos2+$L2);
  $scheck=strtolower($s);
  }
	}
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

?>

 

Usage:

 

<?php

$uls = textbetweenarray("<ul class=\"metaData\">", "</ul>", $content);

?>

 

Then break each <ul> into smaller chunks!

 

:)

 

[edit] Remember that the first <ul> has a class attatched to it! [/edit]

Yeah I think you have enough to work with now. textbetweenarray() simply makes an array with everything between two points. The Live search results are done in list format, which is easier to parse as in my example above.

 

Have a go at doing it yourself :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.