acalder Posted July 26, 2007 Share Posted July 26, 2007 I have created all the files located here:AJAX Live SearchI have checked the code over a number of times (actually, I cut and pasted it) and I still get the following error when I try using it. I am not sure what I might be doing wrong. Any ideas? Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /public_html/ajaxsearch/livesearch.php on line 16 Link to comment Share on other sites More sharing options...
justsomeguy Posted July 27, 2007 Share Posted July 27, 2007 It looks like the livesearch.php file from the w3schools site has some errors in it. Please replace it with this version: <?php$xmlDoc = new DOMDocument();$xmlDoc->load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q) > 0){ $hint=""; for($i=0; $i<($x->length); $i++) { $tmp = $x->item($i); $y = $tmp->getElementsByTagName('title'); $z = $tmp->getElementsByTagName('url'); $item = $y->item(0); if ($item->nodeType == 1) { //find a link matching the search text $child = $item->childNodes->item(0); if (stristr($child->nodeValue,$q)) { if ($hint=="") { $z_item = $z->item(0); $z_child = $z_item->childNodes->item(0); $hint="<a href='" . $z_child->nodeValue . "' target='_blank'>" . $child->nodeValue . "</a>"; } else { $z_item = $z->item(0); $z_child = $z_item->childNodes->item(0); $hint=$hint . "<br /><a href='" . $z_child->nodeValue . "' target='_blank'>" . $child->nodeValue . "</a>"; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == ""){ $response="no suggestion";}else{ $response=$hint;}//output the responseecho $response;?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.