-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax_search.php
40 lines (35 loc) · 1.15 KB
/
ajax_search.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
<?php
/**
* phpDocumentor
*
* PHP Version 5
*
* @category phpDocumentor
* @package Search
* @author Mike van Riel <[email protected]>
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
// get search term
$term = strtolower($_GET['term']);
// find term in XML document
$xml = new DOMDocument();
$xml->load('search_index.xml');
$xpath = new DOMXPath($xml);
$qry = $xpath->query(
"//value[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', "
. "'abcdefghijklmnopqrstuvwxyz'), '$term')]/.."
);
$results = array();
/** @var DOMElement $element */
foreach ($qry as $element) {
/** @var DomNodeList $value */
$value = $element->getElementsByTagName('value');
$id = $element->getElementsByTagName('id');
$type = $element->getElementsByTagName('type');
$results[] = '{ "value": "' . addslashes($value->item(0)->nodeValue)
. '", "id": "' . addslashes($id->item(0)->nodeValue)
. '", "type": "' . addslashes($type->item(0)->nodeValue) . '" }';
}
echo '[' . implode(', ', $results) . ']';