Jump to content

formatting text for a textarea


countdrac

Recommended Posts

hi

 

im trying to format text for a textarea - the text comes from files which are (in essense) the same just what different content

however the textarea is a part of a form so when it gets submitted it needs to be formatted for javascript

 

so as far as i understand i need to strip the string for carriage returns (anything else?) but when i try this...

 

$parsha = $parsha = preg_replace("/\r?\n/", "",$parsha);

 

so this manages to work for about half of the files... but the other half are still not working...

 

the truth is that i dont know if this is getting every carriage return - im not so clued up on regex...

 

can someone please help me out here?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/77134-formatting-text-for-a-textarea/
Share on other sites

I'm not entirely sure but wouldn't nl2br() help here? Again I'm not really sure exactly what you're trying to achieve but I saw "carriage return" so I figured...

 

Though I'm not entirely sure if you can use < b r > in a textarea, I'm not sure if it will parse...

hey

 

i tried nl2br() and still not working

 

im trying to set up a file editing thing where you select a file and it populates a textarea with the contents of the file

 

sometimes it seems though that when i try to use onclick when the save button is hit... basically the data is not passed through

 

so like i said if i do a

 $editFile = preg_replace("/\r?\n/", "\\n",$file); 

 

now about half the files are accepted by the javascript function (i mean the function actually executes...) at the moment it doesnt even get into the function if theres something wrong with the format of the variable it seems...

 

thanks

a text area will auto wrap if a strings length > then the cols, as for forced break lines it is I think a \r\n so what you actualyl want to do is do br2nl not nl2br it isn't a function so you wlil ened to do

str_replace("<br />","\r\n",$string) and str_replace("<br>",\r\b",$string); or a regex version to cover all.

when you replied and said i need a br2nl and said i need the code:

 

str_replace("","\r\n",$string);
str_replace("","\r\b",$string); 

 

i assume you meant

str_replace("\r\n","",$string);
str_replace("\r\b","",$string); 

 

however im still getting the same problems... i think it could be the \r\b... when i try

 

str_replace("\r\b","XXXXXXXXXX",$string);

 

the X's dont show up... am i doing something wrong?

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.