Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Php htmlentities

 
 

Share on Google+Share on Google+

htmlentities

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

htmlentities:

     

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.

Example:

 

<html>

<body>

<?php

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

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

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

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

?>

</body>

</html>

Output:

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

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

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

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: December 17, 2009

Related Tutorials

Discuss: htmlentities  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com