How do I create my own addslashes() style routine for NT directories?

From: Date: Fri, 11 Aug 2000 03:09:59 +0000
Subject: How do I create my own addslashes() style routine for NT directories?
Groups: php.general 
Request: Send a blank email to php-general+get-11261@lists.php.net to get a copy of this message
We have a database that is supposed to store typical NT fashion paths: \\NTSERVER\some\directory\here\ But I can't figure out how in the heck to get it to save and retrieve in tact. If you exectute the code below, you will see the results at the bottom of the page. (I can't get the ereg_replace() function to work). So, it seems that addslashes() is a bit 'too smart' for it's own good. instead of blindly just converting my $script to "set basedir=\\\\NTSERVER\\some\\directory\\here\\ \n" it assumes that I meant to escape the \\ as is written and skips it! grrrr. thereby creating "set basedir=\\NTSERVER\\some\\directory\\here\\ \n" which is close but no cigar. Anyone have a solution around this annoyance? The situation is compounded by the fact that there are in deed characters that I want to be just what they are, such as the \n character. In this case, the add/stripslashes() routines work perfectly. It's only the case of when it sees \\ that it becomes a problem. ------------------ snip backslashes.phtml ------------------ <html><head><title>back slashes</title></head> <body> <?php $script .= "set basedir=\\NTSERVER\some\directory\here\ \n"; $script .= "set anotherdir=\\NTSERVER\some\directory\here\ \n"; ?> <TEXTAREA COLS="80" ROWS="30" WRAP="off"> <?php echo $script; echo "\n\n"; echo "ADDSLASHES -----------------------------------------\n"; $slashedscript = addslashes($script); echo $slashedscript; echo "\n\n"; echo "STRIPSLASHES ---------------------------------------\n"; $unslashedscript = stripslashes($slashedscript); echo $unslashedscript; echo "\n\n"; echo "QUOTEMETA ------------------------------------------\n"; $quotescript = quotemeta($slashedscript); echo $quotescript; echo "\n\n"; echo "EREG_REPLACE ---------------------------------------\n"; $eregscript = ereg_replace("\\","\\\\",$script); echo $eregscript; ?> </TEXTAREA> </body></html> ------------------ snip output ------------------ set basedir=\NTSERVER\some\directory\here\ set anotherdir=\NTSERVER\some\directory\here\ ADDSLASHES ----------------------------------------- set basedir=\\NTSERVER\\some\\directory\\here\\ set anotherdir=\\NTSERVER\\some\\directory\\here\\ STRIPSLASHES --------------------------------------- set basedir=\NTSERVER\some\directory\here\ set anotherdir=\NTSERVER\some\directory\here\ QUOTEMETA ------------------------------------------ set basedir=\\\\NTSERVER\\\\some\\\\directory\\\\here\\\\ set anotherdir=\\\\NTSERVER\\\\some\\\\directory\\\\here\\\\ EREG_REPLACE --------------------------------------- <br> <b>Warning</b>: REG_EESCAPE in <b>/www/html/backslashes.phtml</b> on line <b>28</b><br>

« previous php.general (#11261) next »