retaining format of textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Grahamhart
Forum Commoner
Posts: 27
Joined: Wed Jun 11, 2008 6:05 am

retaining format of textarea

Post 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?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: retaining format of textarea

Post by aceconcepts »

You could use an editor such as FCK editor or try encoding the textarea content i.e. urlencode().
Grahamhart
Forum Commoner
Posts: 27
Joined: Wed Jun 11, 2008 6:05 am

Re: retaining format of textarea

Post by Grahamhart »

I just tryed TinyMCE to write the include file but again it didnt retain, just put in \r\n
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: retaining format of textarea

Post by aceconcepts »

Can you show your code?
Grahamhart
Forum Commoner
Posts: 27
Joined: Wed Jun 11, 2008 6:05 am

Re: retaining format of textarea

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: retaining format of textarea

Post by aceconcepts »

Remover the double quotes from the following line:

Code: Select all

 
$str = "$comments"; 
 
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: retaining format of textarea

Post by alex.barylski »

str_replace should work :)
Grahamhart
Forum Commoner
Posts: 27
Joined: Wed Jun 11, 2008 6:05 am

Re: retaining format of textarea

Post 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
Grahamhart
Forum Commoner
Posts: 27
Joined: Wed Jun 11, 2008 6:05 am

Re: retaining format of textarea

Post 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
Post Reply