Jump to content

Formatted output from SQL


DIMDIGITAL

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.