Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
how to extract the parent directory name from a path
Old 02-25-2010, 12:49 PM how to extract the parent directory name from a path
Junior Talker

Posts: 2
Name: shiva
Trades: 0
For Example let the path be,

$path = "protected/musics/composer/album/song.mp3";
I can extract the file name with the use of basename() function.
$path = basename($path, ".mp3");

Also I want to extract the last two directory names in a variable
example
$composer_name = composer //(extracted from the path $path);
$album_name = album //(extracted from the path $path)

Could you please someone help me out of this? Thanks in advance.
siva1117 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-25-2010, 12:55 PM Re: how to extract the parent directory name from a path
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$pathArr explode('/'$path);
//    0        1        2        3        4
//"protected/musics/composer/album/song.mp3"
$composer $pathArr[2];
$album $pathArr[3]; 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-25-2010, 01:07 PM Re: how to extract the parent directory name from a path
Junior Talker

Posts: 2
Name: shiva
Trades: 0
Hey NullPointer Thank you so much man it works, I'm sorry it may be a silly question I'm a newbie to php.
siva1117 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to how to extract the parent directory name from a path
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14599 seconds with 12 queries