PHP Regex get the last "/" or "\" -


this question has answer here:

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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -