Share on Google+Share on Google+


htmlentities() in php is used to encode the regular html tag to html entities



htmlentities() in php is used to encode the regular html tag to html entities, Whenever we allow users to submit content to the website , we must keep our visitors away from the html coding of our website. Just remember, that when allowing users to submit content to your site you are also giving them access to your website. Be sure you take the proper precautions.

It is always better to use htmlentities to convert regular text into html entities. htmlentities funciton takes the html coding and converts into html entities. For example <tag> will be converted to &lt;tag&gt;

This function has following parameters:

ENT_COMPAT: Converts double quotes and leave single quotes

ENT_QUOTES: Converts double quotes and single quotes

ENT_NOQUOTES: Leave double quotes and single quotes.






$var="\"Rose\" and 'India'";

echo htmlentities($var,ENT_COMPAT)."<BR/>";

echo htmlentities($var,ENT_QUOTES)."<BR/>";

echo htmlentities($var,ENT_NOQUOTES)."<BR/>";





"Rose" and 'India'
"Rose" and 'India'
"Rose" and 'India'

If you check the source code from browser, you would get following output:

&quot;Rose&quot; and 'India'<BR/>&quot;Rose&quot; and &#039;India&#039;<BR/>"Rose" and 'India'<BR/></body>



Posted on: December 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: htmlentities  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image