Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to remove some string from array

    I have an array

    Array
    (
    [0] => SamplePictures/Blue hills.jpg
    [1] => SamplePictures/Sunset.jpg
    [2] => SamplePictures/Water lilies.jpg
    [3] => SamplePictures/Winter.jpg
    )

    at every element of array, you can see the whole path.
    I want to remove the Directory name before image like i only want
    "blue hills.jpg","Sunset.jpg","Water lilies.jpg","Winter.jpg"

    How can i do this

    Please help in this regard

    Eshban

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    $list = array(
        
    "SamplePictures/Blue hills.jpg",
        
    "SamplePictures/Sunset.jpg"
    );

    // this function is called on each item in the array
    function getFileName(&$name$key) {
        
    // set the new value to be everything past the last / in the string
        
    $name substr(strrchr($name'/'), 1) ;
    }

    array_walk($list'getFileName'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •