ERRORS when escaping \ while writing files and echoing to screen

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harryusa
    New Member
    • Oct 2008
    • 14

    #1

    ERRORS when escaping \ while writing files and echoing to screen

    Here I am trying to write a file with a directory path like d:\\$directory1 \$directory2\$f ile.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:
    Code:
    $str="d:\\$directory1\$directory2\$file.txt"
    BUT
    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 :
    Code:
    $str ="d:\\"
    fwrite(fp, $str);
    $str=$directory1;
    fwrite(fp, $str);
    $str="\\";
    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.
    Last edited by Markus; Oct 15 '08, 06:09 PM. Reason: added # tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you could escape the backslashes or put the backslashes in single quotation marks (ie. they will not be parsed as escape character)

    regards

    Comment

    Working...