Danny620 Posted March 8, 2010 Share Posted March 8, 2010 Hi I am trying to code a CMS the thing is when i uses whats to change some text on a page i want somekind of text field like this one where when i click enter it buts <br /> for new line automatilcy. Thanks Link to comment https://forums.phpfreaks.com/topic/194499-need-help-with-textfield/ Share on other sites More sharing options...
danbriant Posted March 8, 2010 Share Posted March 8, 2010 Sounds like you want something like this - http://ckeditor.com/download I currently use it on my site Then you call it like so <script type="text/javascript" src="../ckeditor/ckeditor.js"></script> <script language="javascript" type="text/javascript"> window.onload = function() { CKEDITOR.replace( 'newscontent' ); }; </script> Then make sure you have say newscontent is assigned to a textfield - eg <textarea name="newscontent" id="newscontent" rows="15">'.$newscontent.'</textarea> Ignore my '.$newscontent.' as i use that variable to save and insert new content etc Link to comment https://forums.phpfreaks.com/topic/194499-need-help-with-textfield/#findComment-1022998 Share on other sites More sharing options...
Danny620 Posted March 8, 2010 Author Share Posted March 8, 2010 html form editor that generates html is something i want it has to go into a db something like this <b>New News</b><br /> Hello Everyone<br /> something like that Link to comment https://forums.phpfreaks.com/topic/194499-need-help-with-textfield/#findComment-1023000 Share on other sites More sharing options...
danbriant Posted March 8, 2010 Share Posted March 8, 2010 Well to be honest i think it will be simpler to just use a HTML editor Or try this $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value); http://php.net/manual/en/function.nl2br.php Or something like this $your_string = str_replace(array(chr(10), chr(13)), "<br />", $your_string); Link to comment https://forums.phpfreaks.com/topic/194499-need-help-with-textfield/#findComment-1023001 Share on other sites More sharing options...
danbriant Posted March 8, 2010 Share Posted March 8, 2010 So to basically replace newline with linebreak you use $your_string = str_replace(array(chr(10), chr(13)), "<br />", $your_string); on the value thats going into the database But then when you come to view the data in the text area or whatever it will have linebreaks on it, so to convert back from linebreaks to newline we use this function function br2nl($string) { return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string); } Link to comment https://forums.phpfreaks.com/topic/194499-need-help-with-textfield/#findComment-1023007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.