Page 1 of 1

retaining format of textarea

Posted: Tue Oct 14, 2008 5:50 am
by Grahamhart
Tryed googling this but didnt get far was wondering if any1 had any ideas.

Is it possible to change all occurances of \r\n in a file to there html equivilants as you include the file?

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:10 am
by aceconcepts
You could use an editor such as FCK editor or try encoding the textarea content i.e. urlencode().

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:11 am
by Grahamhart
I just tryed TinyMCE to write the include file but again it didnt retain, just put in \r\n

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:14 am
by aceconcepts
Can you show your code?

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:19 am
by Grahamhart
ok code to take info from textarea and make it an include is as follows, also tryed doing this as .php

$str = "$comments";
file_put_contents("includes/'$thread'.inc", $str);

This include is then called on another page.

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:22 am
by aceconcepts
Remover the double quotes from the following line:

Code: Select all

 
$str = "$comments"; 
 

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 6:23 am
by alex.barylski
str_replace should work :)

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 7:42 am
by Grahamhart
hmm str_replace() doesnt seem to wnat to work for me did this.

$order = array("\r\n", "\n", "\r");
$replace = "<br />";
$str = str_replace($order, $replace, $comments);

yet the \r\n's are still there

Re: retaining format of textarea

Posted: Tue Oct 14, 2008 7:44 am
by Grahamhart
hmm found the problem, i was striping slashes out. which i dont need to do as this doesnt goto an sql database.

thanks