doforumda Posted April 8, 2010 Share Posted April 8, 2010 hi i have this string "../profile_photos/Image0094.jpg" What i want is just to take "Image0094.jpg" and place it in variable. i actually want to unlink this image from profile_photos directory. so how can i delete this image from that directory. if i do it this way "unlink("../profile_photos/Image0094.jpg")" then i think it will delete the whole folder. how to do this? Link to comment https://forums.phpfreaks.com/topic/198008-need-help-with-strings/ Share on other sites More sharing options...
gibigbig Posted April 8, 2010 Share Posted April 8, 2010 You can use an explode function with the "/" as the delimeter, you need to know which array id has the part you want though, in this case the ../profile_photos/Image0094.jpg has three levels so it would look something like this: <?php $value = "../profile_photos/Image0094.jpg"; $broken_up = explode("/",$value); $final = $broken_up[2]; ?> $broken_up[2] means you're using the third variable in the exploded array, ie: Image0094.jpg Link to comment https://forums.phpfreaks.com/topic/198008-need-help-with-strings/#findComment-1039014 Share on other sites More sharing options...
doforumda Posted April 8, 2010 Author Share Posted April 8, 2010 ok now if i do "unlink($final);" then i wont delete that image bcoz i am not mentioning it destination. so how can i mention desitination to avoid directory deletion? Link to comment https://forums.phpfreaks.com/topic/198008-need-help-with-strings/#findComment-1039032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.