<?php

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

/* 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'));
if (
$dapp1a->getError()) {
  die(
$dapp1a->getError());
}

/* Print the URLs of all the search results using the DOM */
$domDoc $dapp1a->getDOM();
if (
$dapp1a->getError()) {
  die(
$dapp1a->getError());
}
$searchResults $domDoc->get_elements_by_tagname('Search_Result');
foreach (
$searchResults as $searchResult) {
  
$titles $searchResult->get_elements_by_tagname('Title');
  foreach (
$titles as $title) {
    echo 
"Search Result URL: ".$title->get_attribute('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');
if (
$dapp1b->getError()) {
  die(
$dapp1b->getError());
}

/* Print the number of search results using the DOM */
$domDoc $dapp1b->getDOM();
if (
$dapp1b->getError()) {
  die(
$dapp1b->getError());
}
$numResultsNodes $domDoc->get_elements_by_tagname('Number_of_Results');
echo 
'Number of results: '.$numResultsNodes[0]->get_content()."\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');
if (
$dapp2->getError()) {
  die(
$dapp2->getError());
}

/* 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'));
if (
$dapp3->getError()) {
  die(
$dapp3->getError());
}

/* Get the translated text using XPath */
$xpath $dapp3->getXPath();
if (
$dapp3->getError()) {
  die(
$dapp3->getError());
}
$translatedTextNodes $xpath->xpath_eval('/elements/Translated_Text');
echo 
$translatedTextNodes->nodeset[0]->get_content()."\n";

?>