changing a sample code
Posted: Wed Oct 06, 2004 3:43 pm
Hi everybody,
I was wondering if anybody can help me out. I consider myself an intermediate php programmer, I do know enough to build a website, but what i don't know (so far) is functions and arrays (i've always built sites where they do not need them)
Anyway, I found a sample script that parses xml into php but i really can't figure out how to change it to how i want it.
Anyway, take a look at my code, it'll be easier that way
as you can see http://www.di.fm/partners/xml/playlists.xml that's the xml page i am using, all i want on my php page is to show this:
Channel: Vocal Trance
Track: (whatever the track is)
Vocal Trance is the first channel on that list, it's the only one i need with the first track.
thank you
I was wondering if anybody can help me out. I consider myself an intermediate php programmer, I do know enough to build a website, but what i don't know (so far) is functions and arrays (i've always built sites where they do not need them)
Anyway, I found a sample script that parses xml into php but i really can't figure out how to change it to how i want it.
Anyway, take a look at my code, it'll be easier that way
Code: Select all
$compiled_langs = array();
$interprt_langs = array();
$flag = '';
$count = 0;
function opening_element($parser, $element, $attributes) {
// opening XML element callback function
global $flag;
if ($element == 'languages')
$flag = $attributes['type'];
}
function closing_element($parser, $element) {
// closing XML element callback function
global $flag;
if ($element == 'languages')
$flag = '';
}
function character_data($parser, $data) {
// callback function for character data
global $flag;
if ($flag == 'compiled') {
global $compiled_langs;
$compiled_langs[] = $data;
}
if ($flag == 'interpreted') {
global $interprt_langs;
$interprt_langs[] = $data;
}
}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, 'opening_element', 'closing_element');
xml_set_character_data_handler($parser, 'character_data');
$document = file('http://www.di.fm/partners/xml/playlists.xml');
foreach ($document as $line) {
xml_parse($parser, $line);
}
xml_parser_free($parser);
printf("The following compiled languages were found...\n");
foreach ($compiled_langs as $name) {
$count++;
printf("%' 3d. %s\n", $count, $name);
}
$count = 0;
printf("\nThe following interpreted languages were found...\n");
foreach ($interprt_langs as $name) {
$count++;
printf("%' 3d. %s\n", $count, $name);
}Channel: Vocal Trance
Track: (whatever the track is)
Vocal Trance is the first channel on that list, it's the only one i need with the first track.
thank you