Jump to content

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";
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.