954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Writing data to rtf file

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['last name']_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
and write to rtf file it shows in the rtf as actual echoed
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
To

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

Mve83
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

how about

$rtf = str_replace("\n",'\par ',$textarea);
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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("","\par ",$value);


the output to rtf is this:


dsfdsfdsfspar par
fdsfdspar par
fdsfpar par
sdf

should be

dsfdsfdsfs
fdsfds
fdsf
sdf

Mve83
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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

Try this:

$rtf = str_replace("\n", "\\par ", $textarea);
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

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

Mve83
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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;
    }
Mve83
Newbie Poster
9 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

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

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You