Jump to content

Archived

This topic is now archived and is closed to further replies.

DIMDIGITAL

Formatted output from SQL

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.