Jump to content

Adding brakes in text type


bigrossco

Recommended Posts

The best way I know of (depending on how your text is getting populated), assuming you're using a textarea, is just to leave the line breaks the user inputs as-is. Then, when you output the record to the screen, run the nl2br() function on the string, and it will convert all the line breaks to <br /> tags to display properly.
Link to comment
Share on other sites

Hopefully this will make more sense:
[code]
<?php
// Let's say I'm pulling comments out of my database:
$sql = mysql_query("SELECT name, email, comment FROM comments");
while ($x = mysql_fetch_array($sql)) {
  $from = "<a href=\"mailto:{$x['email']}\">{$x['name']}</a>";
  $note = nl2br($x['comment']); // This will interpret all my line breaks for me

  // Now, you can display it however you like.
}
?>
[/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.