Jump to content

need help with strings


doforumda

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.