Jump to content

php html into db table


bradkenyon

Recommended Posts

got a question, say you have a textarea, and you put content in there and throw it into a db table, then display it on webpage, if the user hits enter to put a line break in the textarea box of the form, how do i tell it to put it into the db as a line break, and display it on the webpage as a line break.

Link to comment
https://forums.phpfreaks.com/topic/99244-php-html-into-db-table/
Share on other sites

i am making a quick content management system and i want to allow the user to press enter within the text field (textarea) and it will create a line break, like you would in any typical word processor. So it will display the content they typed into the field as w/ the line break from when they pressed enter.

 

i hope i didn't make it too confusing.

nl2br is your best best for this.

 

If you want paragraph breaks as well, trying using regex

 

<?php

$regex = array (
    '/(\\r\\n\\r\\n|\\n\\n)/',
    '/(\\r\\n|\\n)(?!\\r\\n|\\n)/',
    '/_NL_/'
);
$replace = array (
    "</p>_NL_<p>",
    "<br />_NL_",
    "\n"
);

$subject = 'This is a
new line

This is a new
paragraph

Another
paragraph';

$result = preg_replace($regex, $replace, $subject);

echo "<p>$result</p>";


?>

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.