Jump to content

[SOLVED] retrieving info from xml file


thewood68

Recommended Posts

im attaching a sample xml file where i need to retrieve information regarding song artist and song name....this is a long list so there are

lines 17 and 18:

<key>Name</key><string>Rocking Chair</string>

<key>Artist</key><string>PW Gopal</string>

lines 48 and 49:

                          <key>Name</key><string>There Goes My Life</string>

<key>Artist</key><string>Kenny Chesney</string>

etc... these lists could potentially contain 1000's of these brackets. all i want from each one of these is

 

Song Rocking Chair

Artist PW Gopal

 

Song There Goes My Life

Artist Kenny Chesney

 

Thanks

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/88013-solved-retrieving-info-from-xml-file/
Share on other sites

thats definently the right direction... my output for that is.

 

what would i run to filter all the extra out just to get the "PW Gopal"?

 

 

 

array(4) {

  [0]=>

  object(SimpleXMLElement)#2 (1) {

    [0]=>

    string(8) "PW Gopal"

  }

  [1]=>

  object(SimpleXMLElement)#3 (1) {

    [0]=>

    string(13) "Kenny Chesney"

  }

  [2]=>

  object(SimpleXMLElement)#4 (1) {

    [0]=>

    string(11) "Andy Griggs"

  }

  [3]=>

  object(SimpleXMLElement)#5 (1) {

    [0]=>

    string(14) "Colbie Caillat"

  }

}

 

that gives me

Array

(

[PW Gopal] => Rocking Chair

[Kenny Chesney] => There Goes My Life

[Andy Griggs] => She Thinks She Needs Me

[Colbie Caillat] => Bubbly

)

i can definently tell its almost there but im not sure how i would go about dynamically printing out

Artist PW Gopal

Song Rocking Chair

<?php
$f = file_get_contents('Amped.txt');
preg_match_all('/<key>Name<\/key><string>([^<]+)<\/string>[\\n\\r\\t ]*<key>Artist<\/key><string>([^<]+)<\/string>/',$f,$a);
//$b = array_combine($a[2],$a[1]);
//print_r($b);
foreach ($a[1] as $k => $song){
$artist = $a[2][$k];
echo 'Artist: ',$artist,"\n",'Song: ',$song,"\n\n";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.