cve60069 Posted September 20, 2012 Share Posted September 20, 2012 hello I am wanting to write a rtf file using php and the rtf code includes \t and \f commands (see sample.rtf). I wrote index.php to write sample.rtf to a file called print.rtf but the \t and \f were operated on. Is it possible to switch-off php when doing an fwrite(), please? index.phpprint.rtfsample.rtf Link to comment Share on other sites More sharing options...
Ingolme Posted September 20, 2012 Share Posted September 20, 2012 If you put the PHP string within single-quotes they won't be parsed. echo "\t"; // Prints a tabecho '\t'; // Prints "\t"echo "\\t" // Prints "\t" because the backslash is escaped. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 20, 2012 Share Posted September 20, 2012 The problem with your RTF output is the opposite, PHP will see this: {\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}\landscape\paperw15840\paperh12240\margl720\margr720\margt720\margb720\tx720\tx1440\tx2880\tx5760This line is the default color\line\tab this line has 1 tab\line\tab\tab this line has 2 tabs\line\tab\tab\tab this line has 3 tabs\line\tab\tab\tab\tab this line has 4 tabs\line\cf2\tab This line is red and has a tab before it\line\cf1}_END; And convert every "\t" to a tab character, so instead of this: \tab This line is red and has a tab before it\line it will output this: <tab character>ab This line is red and has a tab before it\line Instead of using a heredoc you need to use a nowdoc, so that it does not convert the \t in "\tab" into an actual tab character. A nowdoc acts like a single-quoted string where a heredoc acts like a double-quoted string. To use a nowdoc instead of a heredoc you put the starting identifier in single quotes: $text = <<<'_END' That's the only change you need to make. I read Ingolme's reply wrong, we're talking about the same thing. 1 Link to comment Share on other sites More sharing options...
cve60069 Posted September 21, 2012 Author Share Posted September 21, 2012 Thanks for the advice. I put single quotes around the label and the RTF is perfect. Regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now