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
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.