I wanted to pass a file name, generated by a batch file, to a commandline php script as an argument. Of course, to access local files in Windows, you have to double the backslashes (c:\\blah\\yeah.txt
). It's challenging because the back slash is an escape character.
$fName = $_GET["fileName"]; // yields c:\blah\yeah.txt
$fName = ___TRANSFORM THE SLASHES HERE___; //needs to be c:\\blah\\yeah.txt
$fh = fopen($fName, 'rb');
$feed = fread($fh, filesize($fName));
fclose($fh);
How do you do this using regex?
NOTE: I'm using $_GET
because I wanted to use the parameter name rather than $argv[0]. See hamboy75's note here on the php website.