Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 PHP and XML
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amailer




PostPosted: Sun Apr 25, 2004 4:50 am   Post subject: PHP and XML

Hey all,
Ahh i need help here... hmm this is what im doing.

I got a site where the status of a radio is... now inorder to view that page you have to login.

$server_url = 'http://'.$server['domain'].':'.$server['port'].'/admin.cgi?pass='.$server['pass'].'&mode=viewxml';

i got that... now what i need to do is... use the $server_url and get the information from it and display it.

Basically... how do i '$_GET' the information from the url using XML (because that page is an xml page) and display it on to my page? anyone... or is it confusing?


*i don't know anything to do with XML...
code:

<?php
/* Including the NEEDED files */
include './classes.php';

//
// Please edit the information below (so the script may login and get the xml status)
//
$server['domain'] = 'blabla.com';    // Server domain name (yourdomain.com) DO NOT ADD HTTP:// OR WWW.
$server['pass'] = '****************************';              // Shoutcast server password
$server['port'] = '8000';                // Server port


//
// Please do not EDIT anything below this
// unless you know WHAT YOU ARE DOING!
//

function GetElementByName ($xml, $start, $end) {

   global $pos;
   $startpos = strpos($xml, $start);
   if ($startpos === false) {
       return false;
   }
   $endpos = strpos($xml, $end);
   $endpos = $endpos+strlen($end);   
   $pos = $endpos;
   $endpos = $endpos-$startpos;
   $endpos = $endpos - strlen($end);
   $tag = substr ($xml, $startpos, $endpos);
   $tag = substr ($tag, strlen($start));

   return $tag;

}

/* Setting the server url */
$server_url = 'http://'.$server['domain'].':'.$server['port'].'/admin.cgi?pass='.$server['pass'].'&mode=viewxml';


/* Below we will get the the info from the XML status page :D */
$pos = 0;
$Nodes = array();

if (!($fp = fopen("$server_url", "r"))) {
   die("could not open XML input");
}
while ($getline = fread($fp, 4096)) {
   $data = $data . $getline;
}

$count = 0;
$pos = 0;

// Goes throw XML file and creates an array of all <XML_TAG> tags.
while ($node = GetElementByName($data, "<SHOUTCASTSERVER>", "</SHOUTCASTSERVER>")) {
   $Nodes[$count] = $node;
   $count++;
   $data = substr($data, $pos);
}

// Gets infomation from tag siblings.
for ($i=0; $i<$count; $i++) {
$title = GetElementByName($Nodes[$i], "<SERVERTITLE>", "</SERVERTITLE>");
}

echo $title;


?>



the code above doesn't work... but maby you could edit it... or maby it's just not right..
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Mon Apr 26, 2004 2:24 am   Post subject: (No subject)

PHP docs on XML functions.
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: