Jump to content

Php Ajax Live Search Help


wgcdesigns

Recommended Posts

Good evening,So last i posted i was having issues getting the php to work but got it working! Now im trying to remove the common words from my search but can't get it to work right. Here is what i have so far but the results just dont seem to remove anything much less the words like in, and and so forth..<?php//error_reporting(E_ALL);//ini_set('display_errors', 1); $xmlDoc = new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('entry');//get the q parameter from URL$search_string=$_GET["q"];//remove common words from parameter$search_string = RemoveCommonWords($search_string);function RemoveCommonWords($sText){$CommonWords = array ('at','the','and','of','in');for ($x = 0; $x < count($CommonWords); $x++) {$sText = str_replace(' ' . $CommonWords[$x] . ' ', ' ', $sText);}return $sText;}//lookup all links from the xml file if length of q>0if (strlen($search_string) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="- <a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank' class=Links>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><br />"; } else { $hint=$hint . "<br />- <a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank' class=Links>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><br />"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response="no suggestion"; $response=$search_string; }else { $response=$hint; }//output the responseecho $response;?> Demo At:http://www.thackstonrealty05101.com/index.aspTHANK YOU!

Link to comment
Share on other sites

I found the problem, was using a q and didn't change it to the new parameter name.<?php//error_reporting(E_ALL);//ini_set('display_errors', 1); $xmlDoc = new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('entry');//get the q parameter from URL$search_string=$_GET["q"];//remove common words from parameter$search_string = RemoveCommonWords($search_string);function RemoveCommonWords($sText){$CommonWords = array ('at','the','and','of','in');for ($x = 0; $x < count($CommonWords); $x++) {$sText = str_replace(' ' . $CommonWords[$x] . ' ', ' ', $sText);}return $sText;}//lookup all links from the xml file if length of q>0if (strlen($search_string) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$search_string)) { if ($hint=="") { $hint="- <a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank' class=Links>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><br />"; } else { $hint=$hint . "<br />- <a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank' class=Links>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a><br />"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response=$search_string; }else { $response=$hint; }//output the responseecho $response;?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...