<?php

require_once(dirname(__FILE__).'/../includes/Dapp.php');

// The Dapp constructor throws Exceptions - so we should catch it
try {
  
/* Example 1a: 
   * Perform a MSN search for "good times" using variable arguments*/
  
echo "Performing MSN Search for 'good times' using variable arguments\n";
  
$dapp1a = new Dapp('MSNSearchResults',null,array('good times'));
  
  
/* Print the URLs of all the search results using the DOM */
  
$domDoc $dapp1a->getDOM();
  
$searchResults $domDoc->getElementsByTagName('Search_Result');
  for (
$i 0$i $searchResults->length$i++) {
    
$titles $searchResults->item($i)->getElementsByTagName('Title');
    for (
$j 0$j $titles->length$j++) {
      echo 
"Search Result URL: ".$titles->item($j)->getAttribute('href')."\n";
    }
  }
  echo 
"\n";
  
  
  
  
  
/* Example 1b: 
   * Perform a MSN search for "good times" using an applyToUrl */
  
echo "Performing MSN Search for 'good times' using applyToUrl\n";
  
$dapp1b = new Dapp('MSNSearchResults','http://search.msn.com/results.aspx?q=good%20times');
  
  
/* Print the number of search results using the DOM */
  
$domDoc $dapp1b->getDOM();
  echo 
'Number of results: '.$domDoc->getElementsByTagName('Number_of_Results')->item(0)->nodeValue."\n";
  echo 
"\n";
  
  
 
  
  
/* Example 2:
   * Obtain the content of the main page of Mugglenet - no arguments or applyToUrl 
   * results in running it on the URL stored in the Dapp */
  
echo "Determining size of returned XML for YouTubeMovies\n";
  
$dapp2 = new Dapp('YouTubeMovies');
  
  
/* Print the size in bytes of the XML */
  
echo 'Size in bytes of XML: '.strlen($dapp2->getXML())."\n";
  echo 
"\n";
 
 
  
  
/* Example 3:
   * Translate "Dapper is cool" to French */
  
echo "Translating 'Dapper is cool' to French using Babelfish\n";
  
$dapp3 = new Dapp('Babelfish',null,array('trtext' => 'Dapper is cool',
                                           
'lp'     => 'en_fr'));
  
  
/* Get the translated text using XPath */
  
$xpath $dapp3->getXPath();
  echo 
$xpath->query('/elements/Translated_Text')->item(0)->nodeValue."\n";
  
  
}
catch (
Exception $e) {
  echo 
'Exception: '.get_class($e)."\nMessage: ".$e->getMessage()."\n";
}

?>