Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html/php - format form text to html

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

like image 894
laarsk Avatar asked Mar 02 '26 10:03

laarsk


2 Answers

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

like image 147
Rene Pot Avatar answered Mar 04 '26 23:03

Rene Pot


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

like image 33
Vikas Naranje Avatar answered Mar 04 '26 22:03

Vikas Naranje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!