Page 1 of 1

How to remove some string from array

Posted: Thu Jan 25, 2007 7:53 am
by eshban
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

Posted: Thu Jan 25, 2007 8:25 am
by Grim...

Code: Select all

for ($i = 0; $i < count($array); $i++) 
{
	$array[$i] = str_replace("sampledirectory/", "", $array[$i]);
}

Posted: Thu Jan 25, 2007 8:29 am
by volka
or

Code: Select all

$filenames = array_map('basename', $source);

Posted: Thu Jan 25, 2007 11:28 am
by Kieran Huggins
This is yet another duplicate of his original thread where he simply refuses to look at basename() in the manual.

eshban: this is getting out of hand. Simply posting the same question 5 times is rude, and is unlikely to prompt someone to write your app for you.

Posted: Thu Jan 25, 2007 11:35 am
by John Cartwright
This has been answered elsewhere.

Topic Locked. :roll: