<?php
//Getting the parameter from the snippet call. The default is 0
$input = (isset($input))? $input : 0;
//This function pulls the XML file while sending a user agent to the server.
function get_xml_specify_ua($xml_file_url,$user_agent_string)
{
$result = '';
$opts = array(
'http' => array(
'method' => 'GET',
'header' => "User-Agent: $user_agent_string"
)
);
$context = stream_context_create($opts);
$result = file_get_contents($xml_file_url, false, $context);
return $result;
}
//Calling the above function and sending in the hardcoded parameters
$xml = get_xml_specify_ua(
'http://serverurl.com:8000/admin.cgi?pass=passgoeshere&mode=viewxml&page=4',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6'
);
//Parsing the XML with SimpleXML
$xmlData = new SimpleXMLElement($xml);
//Returning the title from the location specified in $input (passed in through the snippet call)
return $xmlData->SONGHISTORY->SONG[$input]->TITLE;
?>SimpleXML is a built-in function in PHP5; http://us.php.net/simplexml
I don’t see where you’ve included the SimpleXMLElement object class...?
It returns the parameter passed in the call!
Aha. Learn something new every day. What happens if you change the last line to return $input; ?
return $xmlData->SONGHISTORY->SONG[$input]->TITLE;
Yep, that does return something. I know how many cells there are in the Song array so I’ve been using values within its bounds.
Maybe your XML data doesn’t match up to what you’re using in your return statement. Could be just a matter of case or some other annoying little detail like that. Does return $xmlData->SONGHISTORY->SONG[1]->TITLE; return anything?
Quote from: ZAP at Sep 22, 2007, 06:30 PMIt returns the parameter passed in the call!
Aha. Learn something new every day. What happens if you change the last line to return $input; ?
Why would it be having issues with being placed in that line? Right now I literally get nothing returned so there must be a problem in this line;
return $xmlData->SONGHISTORY->SONG[$input]->TITLE;
return $xmlData->SONGHISTORY->SONG[(int)$input]->TITLE;