countdrac Posted November 13, 2007 Share Posted November 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 13, 2007 Share Posted November 13, 2007 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... Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 13, 2007 Author Share Posted November 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 13, 2007 Share Posted November 13, 2007 try $editFile = preg_replace("/[\r\n]+/", "\\n",$file); Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 13, 2007 Author Share Posted November 13, 2007 that it seems to do the same as the $editFile = preg_replace("/\r?\n/", "\\n",$file); the other files still arent going through... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 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. Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 13, 2007 Author Share Posted November 13, 2007 this str_replace("","\r\n",$string) and str_replace("","\r\b",$string); im assuming that its meant to be the other way... replace the \r\n and \r\b with "" but i couldnt get this working... whats the \r\b? i feel im missing something... Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 14, 2007 Author Share Posted November 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.