Helpful Information
 
 
Category: PHP
Inserting html tags into forms

I am using PHP and a mysql database. When entering data into a text area in a form and then inserting into the database, I want html tags to automatically be inserted when for paragraphs that have been entered in a text box. Is there anyway of having the <P> inserted into the code. I presume JavaScript is used for this and not PHP.

Also, does anyone know of any free resources for advanced form input(such as this one), where included is features for Bold and Italics etc?

I am greatful for any help in this :thumbsup:

i think it would be safer to use PHP for this. my friend once had this type of problem and used javascript and he ended up having a db full of crap cos the people had saved the page submitting the form and taken out the javascript

PHP has a built in function to do this, nl2br(). I will move this thred to the PHP forum for further discussion.

Originally posted by JohnKrutsch
PHP has a built in function to do this, nl2br(). I will move this thred to the PHP forum for further discussion.

Thats brilliant. Thank you John

You could also do the following


$something = eregi_replace("\r\n","<br>",addslashes($something));

Then you can place that variable when using the set command on your sql query. Use the br tag instead of the paragraph tag, it will double space your paragraphs otherwise. Hope ths helps.

That is what nl2br() does :)

if you are going to be using the contents of the field in some form of JS then i recommend using ereg, nl2br() simply appends a <br> tag onto the end of every carriage return










privacy (GDPR)