XML file into array line by line?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aquawicket
Forum Newbie
Posts: 1
Joined: Wed Feb 20, 2008 3:52 pm

XML file into array line by line?

Post by aquawicket »

Hi.. I'm trying to load the contents of an XML file into an array line by line unaltered.. But the output of the array is empty.. It shows the right amount of lines.. just empty data.. I believe the < and >'s are to blame as this method works fine with normal text files. And Ideas...

Code: Select all

 
$file = fopen("file.xml","r");
$a = array();
while(! feof($file)){
    array_push($a, fgets($file) );
}
print_r($a);
 
My xml looks something like this

Code: Select all

 
<?xml version="1.0" encoding="UTF-8"?>
<player showDisplay="yes" showPlaylist="yes" autoStart="random">
<song path="http://www.website.com/Music/song1.mp3" title="song1" />
<song path="http://www.website.com/Music/song2.mp3" title="song2" />
</player>
 
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: XML file into array line by line?

Post by John Cartwright »

try file()
Post Reply