DIMDIGITAL Posted April 17, 2006 Share Posted April 17, 2006 I'm making this site and I'm having a problem with output. The users can type in a text that is saved to the sql database and the text is later outputted using the php echo function. My main problem is when out putting the text everything runs togethere in the sense that there are no new paragraphs.For example, this current sentence that you are reading has started a new paragraph with a space between this one and the previous one above. In my case the two paragraphs would be clumped togethere with no space. I think I need to some how save sometype of formatting information in the string. I was testing it and I do know that if I'm typing in the input box and I put html tags like <p><p/>, <span>, etc, when the table(sql) contents are printed out using <?php echo $var_name ?> the html tags are respected and not shown as text. Like if I put hello <p></p> hello. The second hello will start a new paragraph, but I dont think I want users putting html code into the input box so the formatting works. How can I solve this issue?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/7651-formatted-output-from-sql/ Share on other sites More sharing options...
AndyB Posted April 17, 2006 Share Posted April 17, 2006 Basically, put what users enter into your database 'as is' and then when you display it use the [a href=\"http://ca.php.net/manual/en/function.nl2br.php\" target=\"_blank\"]nl2br() function[/a] to convert 'new lines' into html <br> tags:[code]$nice_text = nl2br($text);echo $nice_text;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/7651-formatted-output-from-sql/#findComment-27889 Share on other sites More sharing options...
DIMDIGITAL Posted April 17, 2006 Author Share Posted April 17, 2006 Cool thanks it works. Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/7651-formatted-output-from-sql/#findComment-27895 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.