Writing Database String To File
Posted: Wed Dec 03, 2008 7:41 am
Hi all,
I am trying to take a string from a database , and write it directly to a unix file by calling a simple shell script. Its all very easy but I can do everything but can't stop php messing with my database string. It is constantly reading parts literally, and other parts as being parts that need to be escaped. I don't want any of this. I want the string left untouched and written to file.
My shell script I know to be correct, because if i manually give it this string, hand escaped, it prints it correctly to file exactly.
So here is my code with my already read database value $db_value. My $db_value as seen in phpMyAdmin is the following (its a worst case scenario but I expect my shell script to work with this string exactly as is and untouched).
String in Database
\\\\"\\\\&\\\\'<\\\\>\\\\'\\\'\\'\'
Is this possible? PHP seems to do some removal of the \\\\ and it sees it as \\. The shell script only sees 2 starting \\'s.
Using addslashes($db_value) makes things even worse, because characters like " get a backslash put in front of them then, and my shell script sees too many backslashes (5 starting slashes instead of 4 written to file like \\\\\" instead of \\\\").
There is no combination that will let my shell script receive four simple starting slashes. I either get 2 (php treating \\ as \), or 5 (addslashes adding too many).
Thanks!
I am trying to take a string from a database , and write it directly to a unix file by calling a simple shell script. Its all very easy but I can do everything but can't stop php messing with my database string. It is constantly reading parts literally, and other parts as being parts that need to be escaped. I don't want any of this. I want the string left untouched and written to file.
My shell script I know to be correct, because if i manually give it this string, hand escaped, it prints it correctly to file exactly.
So here is my code with my already read database value $db_value. My $db_value as seen in phpMyAdmin is the following (its a worst case scenario but I expect my shell script to work with this string exactly as is and untouched).
String in Database
\\\\"\\\\&\\\\'<\\\\>\\\\'\\\'\\'\'
Code: Select all
$argument=escapeshellarg($db_value);
$Shell_Command="/tmp/write_file.sh " . $argument;
Using addslashes($db_value) makes things even worse, because characters like " get a backslash put in front of them then, and my shell script sees too many backslashes (5 starting slashes instead of 4 written to file like \\\\\" instead of \\\\").
There is no combination that will let my shell script receive four simple starting slashes. I either get 2 (php treating \\ as \), or 5 (addslashes adding too many).
Thanks!