Help with keyword search script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Help with keyword search script

Post by amir »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Below is a script I use to generate a keywordlist from a search ----- theres one problem when I put in the main keyword to run the search off of- it does not add that main keyword to the list.

QUESTION: How can I get the main keyword used to perform the search with, to be added to the end result keyword list.
EXAMPLE: If I put in "models" as the search term it will return
Modeling
Model
Simulation
Supermodel
Modelling

THE PROBLEM IS THE WORD "models" SHOULD BE THERE TOO.

Code: Select all

function getwords($myKey, $keys='') {
    $search_it=str_replace(' ', '+', $myKey);
   
    $keys = explode('+', strtolower($search_it.'+'.$keys));
   
    $page = strtolower(file_get_contents("http://www.google.com/search?hl=en&q=~$search_it"));

    preg_match_all("/<b>([a-z]+)<\/b>/i",$page,$matches);

    $matches = array_unique(array_slice($matches[1],4));
   
    $found = array();
    foreach($matches as $key => $value) {
      if(!in_array(strtolower($value), $keys))
        $found[] = ucfirst(strtolower($value));
    }
   
    return $found;
  }
 
  $_POST['myKey'] = $_POST['findKey'];
 
  $words = getwords($_POST['myKey']);
 
$iterations = $_POST['iter'];
for($i = 2; $i <= $iterations; $i++) {
  foreach($words as $w) {
    $disallow = $_POST['myKey'].'+'.implode('+', $words);
    $words = array_unique(array_merge($words, getwords($w, $disallow)));
  }
}
 
    echo'<form action="sendfile.php" method="POST" name="allResult">';

$i=1;
foreach($words as $w){
    echo "<input type=\"checkbox\" name=\"chk$i\" value=\"$w\">$w<br>";
    $i++;
}

 if(isset($_POST['findKey'])){
echo"<br><input type=\"submit\" name=\"submit\" value=\"Create Text File\">";
}


  echo'</form>';
echo"There are $i Keywords.";

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Please use

Code: Select all

[url=http://forums.devnetwork.net/faq.php?mode=bbcode]bbcode tags[/url].

google provides an api to access there search engine, see http://code.google.com/apis.html
amir
Forum Contributor
Posts: 287
Joined: Sat Oct 07, 2006 4:28 pm

Post by amir »

Thanks,
next time, i 'll try to embed the PHP code in it
Post Reply