PHP Regex get the last "/" or "\" -
this question has answer here:
- how last part of url string? 1 answer
i have set of data following
c://path/path/path/path/xyz.jpg
or
c://path/path/path/path\xyz.jpg
using preg_replace('/(^.*\/)|(^.*\\)/gi', '', $path);
i able run in online tester (eg http://www.regextester.com/) won't work in php code, please help.
you need remove g modifier , double escape \
:
$file = preg_replace('/(^.*\/)|(^.*\\\\)/', '', $path);
or
$file = preg_replace('~^.*[/\\\\]~', '', $path);
Comments
Post a Comment