php


PHP code not creating new line in rtf template


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;
?>
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.
It's likely that this may have something to do with your content type. I'd replace application/msword with application/rtf Then your associated RTF application will at least be rendering it based on the correct MIME type.
When I tried this on my server just now, it rendered in Word with the line break just fine.

Related Links

How can I implement RSS 2 in Code Igniter?
Error with MySQL syntax using REPLACE INTO
how to store chechbox value in php
mysql muliple queries in one statement
PHP Static Variables
php code analysis
PHP Object Validation
How to use cms systems like drupal and so on for crawl only? [closed]
How do I loop through MySQL results easily?
Accessing Mac applications from Ruby or PHP or Cocoa
How do I run PHP code when a user clicks on a link?
How do you just get the vars in a url using php?
ArrayCollection in PHP
Recursively build XML from PSQL Result Set (using PHP)
How to display weekly(Mon to Sun) data in php and mysql?
Escape double quotes of HTML attributes output by PHP

Categories

HOME
office365
memory
plesk
jms
websocket
tcp
fogbugz
elk-stack
ontology
openfoam
fedora
hspi
siesta
spring-amqp
pushdown-automaton
dma
mahout-recommender
android-5.1.1-lollipop
google-sites
cpu-usage
jest
spring-ldap
activeadmin
multi-upload
amazon-sns
acl
sybase-ase
clipboard
tf-idf
django-import-export
social-networking
toad
argv
delayed-job
xcrun
listjs
directfb
pdfminer
pdfnet
love2d
jade4j
variable-variables
export-to-pdf
git-tfs
nuclio
bit-shift
linq-to-excel
rm
htmlspecialchars
pen
dynamics-crm-4
nitrousio
streamwriter
svnserve
ftp-client
android-sdcard
perforce-integrate
android-syncadapter
swiffy
gridbaglayout
currency-exchange-rates
psd
onepage-checkout
wikimedia-commons
perceptron
smart-tv
blockquote
gql
fantom
embeddedwebserver
relational-model
kefir.js
symja
ecos
network-printers
jini
refit
preorder
jms-serializer
jmenubar
visual-c++-2005
grails-2.3
oscilloscope
ofstream
asp.net-mvc-3-areas
ip-geolocation
image-formats
kaazing
java.lang.class
sigar
microblogging
zend-server-ce
differentiation
asio
net-use
bass
chunking
cassini
fxruby
gtktextview

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App