I want to know the function that can perform the following operation
$str = “uploads/file/file1.jpg”;
i want to slash the initial of the string uploads/file/ and just want to return file1.jpg as value.
i tried using str_replace(),
$str = "uploads/file/file1.jpg";
$str2 = str_replace("uploads/file"," ", $str);
echo $str;
this is not working, where i am going wrong?
EDIT : Silly me i was not noticing that i was trying to echo $str, sorry for this. it is working for me now.
BTW i want to know which method is better the above one or the basename();
Use
basename(): It is designed specifically to get the file name part out of a path.Also interesting (although not necessary in this examle) is
pathinfo()which splits a string into four components: Directory, base name, file name, and extension.The equivalent to split URLs into their components is
parse_url().