tags:

views:

74

answers:

2

Hi,

I'm migrating a old (circa 2001) PHP 3 app to a new PHP5 server. 90% of the code worked right out of the box after migration and most of the remaining bit worked once I went through the old php.ini and changed settings in the new php.ini to match. Still there's one really annoying thing. One of the major things the app does is create RTF documents by mashing together information from the MySQL database and RTF templates that are embedded in php scripts. The original author used echo statements that have PHP variable references and RTF mixed together to output a file to the browser, which then calls Word to handle the output.

My problem is that in the new system whenever the echo statement has \f, the actual output has a linebreak. I'm not certain if it is a CR or LF but it's definitely a linebreak. Is this a PHP thing to process the \f? How can I turn it off?

A: 

\f is a form feed. It's equivalent to the ASCII code 12. See the full table at Wikipedia. If you were to print your RTF doc the printer should go to the next page. If you are looking at the document in a WYSIWYG editor such as Microsoft Word, it should show that the doc skips to the next page.

The \f is not a PHP thing specifically. If you don't actually want form feeds, get rid of the \f's.

Tony Miller
RTF uses \f for something else. This isn't "\f" character (like \n would be) but two ASCII characters as read by an RTF parser. As well as I can tell from the RTF specs it has something to do with changing the font used in the text following it.
hofo
+1  A: 

According to the PHP documentation the "\f" in a double-quoted string stands for a FORM-FEED since version 5.2.5.

Thus, if you want to actually have "\f" in your output, you will need to use "\\f", as in:

echo "Test\\f";
paracycle
Thanks. I tried looking in the PHP docs but I guess I didn't use the right search strings. There's got to be some way of turning off that behavior however, as the same PHP code running on the PHP 4.x server doesn't exhibit this behavior.
hofo
Oh, I see from the docs this is a behavior introduced in version PHP 5.2.5. I guess I'll do a mass search and replace as that \f is needed for the RTF itself. Thanks.
hofo
No problems. I had missed the PHP version in the document. I updated the answer to include that fact as well. Happy coding!
paracycle