Need help with returning filename from an array

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
G3mInI
Forum Newbie
Posts: 1
Joined: Sat Dec 19, 2009 6:27 am

Need help with returning filename from an array

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help with returning filename from an array

Post 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);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply