By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

ERRORS when escaping \ while writing files and echoing to screen

P: 14
Here I am trying to write a file with a directory path like d:\\$directory1\$directory2\$file.txt
So I have variables in between backslashes and I keep getting errors like:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/4/4/a/2769/2769/public_html/upload/a/thankyou.php on line 69

I would like put the values in a literal string variable like:
Expand|Select|Wrap|Line Numbers
  1. $str="d:\\$directory1\$directory2\$file.txt" 
I believe this might not be possible so in the meantime I have been writing each component to the file one piece at a time :
Expand|Select|Wrap|Line Numbers
  1. $str ="d:\\"
  2. fwrite(fp, $str);
  3. $str=$directory1;
  4. fwrite(fp, $str);
  5. $str="\\";
  6. fwrite(fp, $str);
...and so on, that isn't working right either, I keep getting a \\ in the file instead of \ or errors depending on my syntax.
Oct 15 '08 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
you could escape the backslashes or put the backslashes in single quotation marks (ie. they will not be parsed as escape character)

Oct 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.