I have this textfield in a html form, which I want to insert into my MySQL database using php. But, I want the typed text to get HTML formatting, so I can easily display it on my website. How can I do this?
The row where it should be inserted into the MySQL database is of the type: text.
The reason I want to know this, is because normally a textfield doesnt output linebreaks...
IF you want to have the newlines, use the PHP function nl2br() so you will get the new lines.
If any HTML is typed into that box. you will get it.
However, I recommend not storing the <br> or HTML tags you add manually to the database, but do it later. The nl2br() function should be called after you get it from the database.
Documentation: http://www.php.net/manual/en/function.nl2br.php
you can use this function to store in database
$a = htmlentities($orig);
http://php.net/manual/en/function.htmlentities.php
use this function when fetch data from database to show on page
$b = html_entity_decode($a);
http://php.net/manual/en/function.html-entity-decode.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With