alexville Posted April 27, 2007 Share Posted April 27, 2007 Hello, I was wondering if there is a such thing that lets users input text into a html form input box, but when they start a new line or something, it inputs "<p>" when is outputed to php. So that the text that they inputed will look exactly the same on a php's output. Its sort of like this forum's way of inputting text. Quote Link to comment Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 tinymce is the best ;-) Quote Link to comment Share on other sites More sharing options...
alexville Posted April 27, 2007 Author Share Posted April 27, 2007 Alright, I'll try it out Quote Link to comment Share on other sites More sharing options...
kidintraffic Posted April 27, 2007 Share Posted April 27, 2007 Kind of on the same topic... Is there a way to display text exactly as the user entered it in a form after it has been saved to the database. I'm having a problem now that if you enter a few paragraphs of info into a form field, then display the data onto another page from the database, the paragraphs are all together with no lines in between each paragraph. If I enter a break tag after a paragraph or put paragraph tags around each paragraph, the info is diplayed correctly. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 27, 2007 Share Posted April 27, 2007 You need to process the input from the user and replace line breaks with BR tags. You can do this before saving to the database or do it when you display the databse results to the page. The other option is to display using PRE so that the text is displayed exactly as it was enetered. But, you lose some functionality related to display - I find it mostly useful for displaying code to a page. Quote Link to comment Share on other sites More sharing options...
alexville Posted April 27, 2007 Author Share Posted April 27, 2007 You need to process the input from the user and replace line breaks with BR tags. You can do this before saving to the database or do it when you display the databse results to the page. The other option is to display using PRE so that the text is displayed exactly as it was enetered. But, you lose some functionality related to display - I find it mostly useful for displaying code to a page. What would you use to process the BR tags? Quote Link to comment Share on other sites More sharing options...
bgoulette612 Posted April 27, 2007 Share Posted April 27, 2007 You need to process the input from the user and replace line breaks with BR tags. You can do this before saving to the database or do it when you display the databse results to the page. The other option is to display using PRE so that the text is displayed exactly as it was enetered. But, you lose some functionality related to display - I find it mostly useful for displaying code to a page. What would you use to process the BR tags? There's always nl2br (http://us2.php.net/manual/en/function.nl2br.php). I usually take the arguably unnecessary step of running everything though a series of regular expressions, for example: $sOutput = preg_replace('/\\n/', '<br />', $sInput); The above is basically a waste of time since it's functionally what nl2br does (as far as I'm aware). Sometimes, I'll do this instead: $sOutput = preg_replace('/\\n\\n/si', '<\p><p>', $sInput); // Do this first to capture any double newlines. $sOutput = preg_replace('/\\n/si', '<br />', $sInput); // Assume single newlines are meant to be breaks, not paragraphs. $sOutput = "<p>".$sOutput."</p>"; I haven't tested any of the above, but I'm pretty sure that'll work...Might be overkill. Anyway, that's my two cents. Oh yeah: if you wanted to make sure multiple newlines were treated as just a new paragraph, you could change the above code to this: ... $sOutput = preg_replace('/\\n(\\n+)+/si', '</p><p>', $sInput); // Do this first to capture any multiple (more than one) newlines. ... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 27, 2007 Share Posted April 27, 2007 just use nl2br() when the text is outputted, exaple: echo nl2br($row['users_text']); 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.