i need to get filename from file path string. For example, from this string \abc\def\filename.txt i need to get filename.txt
trying to do this with regexp:
$filepath="abc\filename.txt";
$filename = preg_replace("/.+\\/","",$filepath);
but it gives me an error. What regex i should use to solve this?
you should use the function basename instead:
edit: important note, you need to use single quotes when you have backslashes in your strings, else escape them properly.
note: this will not work:
because you’re variable $filepath infact holds:
abc[special char here equalling \f]ilename.txtanother edit:
this regex works too..
all that was wrong with your original was that you had double-quotes rather than single, and backslash needs double escaped (\\ rather than \).