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.
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]

Archived

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

×
×
  • 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.