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

Laravel GoCardless
PHP round minutes when hour ends
PHP Image Change to Silhouette
FB Login: URL changes to random String after login
Update data to related tables yii2
How to tell if a query is empty? [duplicate]
Using PHP to extract specific data from websites
send post from JsonArrayRequest volley to server not working
PHP MongoDB `fields` param not working
How to run a laravel git clone in local
String Padding Not Calculating as Expected
Search Form Option as Table Name (COUNT & QUERY) [duplicate]
Disabling email verification in sylius platform
Symfony Url Generator producing different URLs from the same Route before and after login
Could not run PHP files inside the crontab for ubuntu server
echo php foreach loop result by 3 different row data

Categories

HOME
php
jboss
android-studio
dotnetnuke
seedstack
softlayer
hdfs
embedded-resource
typeerror
fogbugz
ag-grid
phpseclib
lda
alljoyn
phpstorm-2017.1
graphdb
ex
pushdown-automaton
dma
asp.net-core-1.0
gravity
exec-maven-plugin
jaspersoft-studio
gmp
nullreferenceexception
parceler
social-tables
sqlplus
web-push
jpa-2.1
unordered-multimap
beego
oracleforms
amazon-iam
objectmapper
premake
commonsware-cwac
nanogallery
identify
elastica
microsoft-ui-automation
llvm-ir
assert
get-event-store
jqgrid-asp.net
type-inference
doctrine-extensions
gcal
cyanogenmod
scala-breeze
password-hash
redisson
solr-query-syntax
android-sharing
webvtt
email-forwarding
gmaps.js
annotatorjs
s-function
bilinear-interpolation
jtag
maven-release-plugin
codecharge
vimperator
servicestack-bsd
python-cffi
chicagoboss
http.client
netdatacontractserializer
wlanapi
google-gdk
mutators
nanomsg
phonegap-facebook-plugin
osascript
prism.js
proxy-server
saga
eclim
ldif
aero
mongo-jackson-mapper
user-forums
servercontrol
vows
qt-mobility
uipasteboard
gaelyk
inversion
downcasting
rakudo
jvm-bytecode

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App