Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP code not creating new line in rtf template

Tags:

php

I reduced a php script to the exact code necessary to solve a perplexing problem (at least to me!). All the script below is supposed to do is replace '++name' in an rtf template with a hard coded variable that will print 'me' on one line, and 'you' on the next line. Besides trying "\r\n" to create the new line, I've also tried "\par" to no avail. The below code replaces '++name' with "meyou" on one line. I have found a number of "solutions" on stackoverflow and other forums, but none have worked for me.

Any help is much appreciated.

    <?php
    $name = "me" . "\r\n" . "you";
    header('Content-type: application/msword');
    header('Content-Disposition: inline, filename=filenot.rtf');
    $filename = 'rtfnotice.rtf';
    $fp = fopen ($filename, 'r');
    $output = fread( $fp, filesize($filename));
    fclose ($fp);
    $output = str_replace('++name', $name, $output);
    echo $output;
?>
like image 263
Arlene K Avatar asked May 19 '26 21:05

Arlene K


1 Answers

With RTF, each formatted section is enclosed in mustaches. The "formatting" is placed at the beginnning. So to make something bold, {\b hey, this text is bold}

To output "me" and "you" on seperate lines, you can put {\pard\par} between them, or you can make them their own paragraphs. {\pard me \par}{\pard you \par}

I think, you can also simply put \line. Isn't RTF fun?

Some time ago I wrote a library for outputting RTF. You may find my "format" function useful. Basically you supply a bunch of properties to the text and it outputs it in RTF. This is AS3, but pretty eays to translate to PHP.

like image 92
Jonathan Rowny Avatar answered May 21 '26 11:05

Jonathan Rowny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!