-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlivesearch.php
50 lines (44 loc) · 1.58 KB
/
livesearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("assets/xml/links.html");
$x=$xmlDoc->getElementsByTagName('link');;
//get the q parameter from URL
$q=$_GET["q"];
//lookup all links from the xml file
$hint='';
if (strlen($q)>0) {
for($i=0; $i<($x->length); $i++) {
$y=$x->item($i)->getElementsByTagName('title');
$c=$x->item($i)->getElementsByTagName('content');
$z=$x->item($i)->getElementsByTagName('url');
$ystr =stristr($y->item(0)->childNodes->item(0)->nodeValue,$q) ;
$cstr =stristr($c->item(0)->childNodes->item(0)->nodeValue,$q) ;
if ($y->item(0)->nodeType==1 OR $c->item(0)->nodeType==1) {
//find a link matching the search text
if ($ystr OR $cstr) {
if ($hint=="") {
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"'>" .
$y->item(0)->childNodes->item(0)->nodeValue .
"</a><label hidden>" . $c->item(0)->childNodes->item(0)->nodeValue . "</label>";
} else {
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
"'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a><label disable hidden>". $c->item(0)->childNodes->item(0)->nodeValue ."</label>";
}
}
}
}
}
// Set output to "no suggestion" if no hint was found
// or to the correct values
if ($hint=='' OR $hint==' ') {
$response="<p class='nohoverlivesearch'>There are no results. Check your spelling or try different keywords...</p>";
} else {
$response = $hint;
//output the response
}
echo $response;
?>