How to remove some string from array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
eshban
Forum Contributor
Posts: 184
Joined: Mon Sep 05, 2005 1:38 am

How to remove some string from array

Post 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
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Code: Select all

for ($i = 0; $i < count($array); $i++) 
{
	$array[$i] = str_replace("sampledirectory/", "", $array[$i]);
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

or

Code: Select all

$filenames = array_map('basename', $source);
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This has been answered elsewhere.

Topic Locked. :roll:
Locked