...

View Full Version : How to remove some string from array



eshban
01-25-2007, 02:50 PM
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

aedrin
01-25-2007, 04:40 PM
$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');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum