Page 1 of 1

Need help with returning filename from an array

Posted: Sat Dec 19, 2009 6:42 am
by G3mInI
I am attempting to write some code to populate a flash mp3 player.

I have the following variable:

Code: Select all

$data = http://www.site.com/song1.mp3|http://ww ... /song4.mp3
I know as much to do:

Code: Select all

$playlist = explode("|", $data)
.. which should give me $playlist as an array of urls. What I need to do is create a variable that contains an array that would look like the following:

Code: Select all

song1|song2|song3|song4
Then I could pass this variable to the title variable of the player.

I have been beating my brains out with the php manual trying to understand basename, pathinfo and other php functions but all I am accomplishing is becoming more confused.

Can someone help me with getting $playlist to be song1|song2|song3... etc?

Thanks in advance,
G3mInI

Re: Need help with returning filename from an array

Posted: Sun Dec 20, 2009 10:08 am
by AbraCadaver
I'm not sure if you want an array or an imploded list, but this should help:

Code: Select all

$data = 'http://www.site.com/song1.mp3|http://www.site.com/song2.mp3|http://www.site.com/song3.mp3|http://www.site.com/song4.mp3';
 
$playlist = explode('|', $data);
print_r($playlist);
 
$playlist = array_map('basename', $playlist);
print_r($playlist);
 
$playlist = implode('|', $playlist);
print_r($playlist);