IamMeCone Posted May 11, 2008 Share Posted May 11, 2008 Ok, i have not clue what i did wrong. I am working on a search engine that gets it's data from an xml file the xml format is <word>page1,page2.html> i don't worry about how many times the word occurs in the page however i do want to display the pages with more than one queryed words on it it seems to work most of the time when i give it one or two words but anything over that repeats one result the the next result three times $search is an array of the pages that match up with the query $terms is an array of each term separatly $num is how many times each page occurs that lines up side to side with $search like this $search[0]=the page $num[0]= how many words the page has that maches up to the terms here is the php <?php function array_check ($array, $string) { $foo; for ($i = 0; $i <= count($array); $i++) { if ($array[$i] == $string) { $foo=1; } else { $foo=0; } return $foo; } } function array_pos ($array, $string) { $foo; for ($i = 0; $i <= count($array); $i++) { if ($array[$i] == $string) { return $i; } } } $xml = new SimpleXMLElement(file_get_contents('db.xml')); $search= array(); $num = array(); $terms= explode(" ",(string)$_GET['q']); for ($s = 0; $s <= count($terms); $s++) { if($xml->$terms[$s]) { $res=explode(",",$xml->$terms[$s]); $i=0; for ($t = 0; $t <= count($res)-1; $t++) { if(array_check($search,$res[$t])==1) { $num[array_pos($search,$res[$t])]+=1; } else if(array_check($search,$res[$t])==0) { $search[count($search)] =$res[$t]; $num[count($num)] =1; } } } } print_r($search); echo "<br>"; print_r($num); echo "<br>"; for ($y =0; $y <= count($terms); $y++) { for ($q =0; $q <= count($search)-1; $q++) { if($num[$q] == $y) { echo "<a href=\"".$search[$y]."\">".$search[$y]."</a> <br>"; } } } ?> here is the example xml file <?xml version="1.0" encoding="utf-8"?> <searchdb> <under>index.html</under> <over>smart.html</over> <death>index.html</death> <cool>index.html</cool> <nice>smart.html</nice> <boo>foo.html</boo> </searchdb> could somone please help me out here Link to comment https://forums.phpfreaks.com/topic/105145-php-search-engine-with-xml-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.