PHP Classes

File: doc/ajax_search.php

Recommend this page to a friend!
  Classes of Everton da Rosa   PHP4Console   doc/ajax_search.php   Download  
File: doc/ajax_search.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP4Console
Render text and shapes in a terminal console
Author: By
Last change: Update of doc/ajax_search.php
Date: 5 months ago
Size: 1,181 bytes
 

Contents

Class file image Download
<?php
/**
 * phpDocumentor
 *
 * PHP Version 5
 *
 * @category phpDocumentor
 * @package Search
 * @author Mike van Riel <mike.vanriel@naenius.com>
 * @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) . ']';