-1

I have a 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 am able to run it in online tester (eg http://www.regextester.com/) but it won't work in my PHP code, please help.

aahhaa
  • 2,240
  • 3
  • 19
  • 30

1 Answers1

1

You need to remove the g modifier and double escape the \:

$file = preg_replace('/(^.*\/)|(^.*\\\\)/', '', $path);

or

$file = preg_replace('~^.*[/\\\\]~', '', $path);
Toto
  • 89,455
  • 62
  • 89
  • 125