hi please can someone help?

I have designed an applicant form that posts data to session variables then at the end of the application it puts all session variables in an array.

I then have a template.rtf file which I copy and rename to $_session_timestamp.rtf

I then open for writing

I have a function that searches the opened document for placeholders %%placeholder name%% and replace with relevant array data. This works great except for one annoying issue.

Some of the array data has come from text area field with new lines needed. When I us nl2br to turn the \n to <br /> and write to rtf file it shows in the rtf as actual echoed <br /> rather than putting the text following the tag on a new line. If I don't use nl2br it prints all the data on one line. This means you get words like the decidedto rather than decided

Is there a way to get the formatting right? Please help in plain English I am not a good interpreter of really techie answers thanks

6 Years
Discussion Span
Last Post by diafol

how about

$rtf = str_replace("\n",'\par ',$textarea);

Hi I tried this now and in RTF now it breaks the line but actually prints the word par any suggestions?

this is the code I put in the \n didn't work

value = str_replace("<br />","\par ",$value);

the output to rtf is this:

dsfdsfdsfspar par
fdsfdspar par
fdsfpar par

should be



Could I ask, why is there a <br /> in the string anyway? If the text is coming from a textarea - don't use nl2br.

Try this:

$rtf = str_replace("\n", "\\par ", $textarea);

Edited by diafol: n/a


Hi when I tried the previous time with \n it gave me tabbed spaces so changed n to br. Then got that result I'll try this again. Thanks for your quick and continued support on this


Hi Tried this and no luck still. here is full function code

function modifier($vars, $rftfile) {
        $xchange = array ('\\' => "\\\\",
                               '{'  => "\{",
                               '}'  => "\}");
        $document = file_get_contents($rftfile);
        if(!$document) {
            return false;
        foreach($vars as $key=>$value) {
            $search = "%%".strtoupper($key)."%%";
            foreach($xchange as $orig => $replace) {
                if ($value == "Select" || "" ){
                    $value ="";
                }else {
                    $value = (stripslashes($value));
                    $value = str_replace("\r\n",' ',$value);
                $value = str_replace($orig, $replace, $value);
            $document = str_replace($search, $value, $document);
        return $document;

str_replace takes arrays as parameters- so prob. no need for your loops

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.