robcrozier Posted August 16, 2006 Share Posted August 16, 2006 ok guys here's the situation...i want to be able to input preformatted text into a form textarea which i will then return as a variable to insert into my database. This text block (complete with line feeds etc) will then be used in various other pages. im ok with actually returning the variable from the form and inserting it into the database, however i can't return it as preformatted text with all line feeds etc in tact. It just all mushes together into one big paragraph!!!can any one help??? Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/ Share on other sites More sharing options...
tomfmason Posted August 16, 2006 Share Posted August 16, 2006 I think [url=http://us3.php.net/manual/en/function.wordwrap.php]wordwrap[/url] is what you are looking for. So, for instance if you want the text to be 50 spaces wide then you would do this. [code=php:0]$newtext = wordwrap($text, 50, "<br />\n");[/code]Hope this helps.TOm Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75600 Share on other sites More sharing options...
robcrozier Posted August 16, 2006 Author Share Posted August 16, 2006 hi, thanks for that but i dont just want to determine the overall width of the text block to be returned from the textarea. i want to return all the 'return key presses' that the user inputs into the textarea. Meaning that the returned output will display exactly as the user has entered it into the textarea. hope this makes it a bit clearer. Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75601 Share on other sites More sharing options...
tomfmason Posted August 16, 2006 Share Posted August 16, 2006 I don't know. That is a good question. I will test a few things and see if I can figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75604 Share on other sites More sharing options...
robcrozier Posted August 16, 2006 Author Share Posted August 16, 2006 Thanks mate, PLEASE let me know if you come up with anything ........ its driving me mad now!!! >:( Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75605 Share on other sites More sharing options...
wildteen88 Posted August 16, 2006 Share Posted August 16, 2006 Use nl2br this convets line breaks into their HTML equivalent (< br /> (without the space)). Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75619 Share on other sites More sharing options...
Jenk Posted August 16, 2006 Share Posted August 16, 2006 [code]<?php$query = "INSERT INTO `table` VALUES ('" . mysql_real_escape_string($_POST['textarea']) . "')";echo '<textarea>' . nl2br(htmlentities($_POST['textarea'])) . '</textarea>';?>[/code]btw, nl2br() is the equivalent of [code]<?phpfunction nl2br ($string) { return str_replace("\n", "<br />\n", $string);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75638 Share on other sites More sharing options...
robcrozier Posted August 16, 2006 Author Share Posted August 16, 2006 Cheers, that worked! ;D Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75674 Share on other sites More sharing options...
wildteen88 Posted August 16, 2006 Share Posted August 16, 2006 [quote author=Jenk link=topic=104474.msg416770#msg416770 date=1155731251][code]<?php$query = "INSERT INTO `table` VALUES ('" . mysql_real_escape_string($_POST['textarea']) . "')";echo '<textarea>' . nl2br(htmlentities($_POST['textarea'])) . '</textarea>';?>[/code]btw, nl2br() is the equivalent of [code]<?phpfunction nl2br ($string) { return str_replace("\n", "<br />\n", $string);}?>[/code][/quote]It doesnt just replace the \n character but '\r\n' (Windows), '\r' (Mac) and '\n' (Linux) Quote Link to comment https://forums.phpfreaks.com/topic/17723-returning-preformatted-text-from-a-textarea-to-insert-into-a-database/#findComment-75693 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.