how to extract the parent directory name from a path

Discussion in 'PHP' started by kuttappan, May 10, 2010.

  1. #1
    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.
     
    kuttappan, May 10, 2010 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Bohra, May 10, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    danx10, May 10, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    dirname !!
     
    gapz101, May 11, 2010 IP