Services_OpenSearch
[ class tree: Services_OpenSearch ] [ index: Services_OpenSearch ] [ all elements ]

Source for file example.php

Documentation is available at example.php

  1. #!/usr/bin/env php
  2. <?php
  3. ini_set('error_reporting',E_ALL);
  4.  
  5. require_once 'Services/OpenSearch.php';
  6.  
  7. $desc_url = array(
  8.     // Koders Source Code Search / OpenSearch 1.0
  9.     'koders'    => 'http://www.koders.com/search/KodersSourceCodeSearchDescription.xml',
  10.     // Wikipedia (English)       / OpenSearch 1.1
  11.     'wikipedia' => 'http://en.wikipedia.org/w/opensearch_desc.php',
  12.     );
  13.  
  14. $url 'http://www.koders.com/search/KodersSourceCodeSearchDescription.xml';
  15. if ($argc >= 2 && isset($desc_url$argv[1] ])) {
  16.     $url $desc_url$argv[1] ];
  17. }
  18.  
  19. $os = new Services_OpenSearch($url);
  20.  
  21. $word 'PHP';
  22.  
  23. $url $os->getSearchURLfor($word);
  24. print_r($url);
  25.  
  26. $result $os->search($word);
  27.  
  28. if (is_array($result)) {
  29.     // RSS or Atom
  30.     $n = 1;
  31.     foreach ($result as $item{
  32.         echo "[$n] {$item['title']}\n{$item['link']}\n\n";
  33.         $n++;
  34.     }
  35. else if (is_string($result)) {
  36.     // HTML or XHTML
  37.     echo substr($result,0,400),"\n";
  38. else {
  39.     die("hmmm");
  40. }
  41. ?>

Documentation generated on Mon, 11 Mar 2019 15:16:30 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.