ScoTTy_XY Posted October 11, 2007 Share Posted October 11, 2007 Hey guys I was wondering if you could please help a noob learn abit more about php. I have a mysql database with a text column in it. When browsed within the structure of the database the text is formatted as it was entered with spaces and new lines etc. But when i retrieve the text into a php variable and try and display it within a paragraph all the text becomes one big block. I was wondering if someone could please give me a lesson on retaining all the formatting in terms of spaces and new lines (enters). I want to display the text exactly as it is entered. Rather than compressed into one big paragraph. Any help would be much appreciated. Cheers guys Dale Quote Link to comment https://forums.phpfreaks.com/topic/72747-php-noob-needs-help-with-some-string-formatting/ Share on other sites More sharing options...
benji87 Posted October 11, 2007 Share Posted October 11, 2007 This is something ive not long learnt but i know this code works for a fact as im using it right now. So i cant really explain it all, but hey it works! Once you have registered you're text from the database for example $text=mysql_result($result,$i,"text");[code] (You may have done this differently) Then you need to use php explode to include line breaks. This code also includes a number to limit the amount of characters displayed, which is always useful. Just set it to your own needs as you can see mine is set at 1500 characters: [code]$text = wordwrap($text, 1500, "|", 1); list($text) = explode('|', $text); Then when you come to echo the text this is what you need to put <? echo nl2br("$text") ?> [/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/72747-php-noob-needs-help-with-some-string-formatting/#findComment-366899 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.