Home Php htmlentities



htmlentities
Posted on: December 17, 2009 at 12:00 AM
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>
 

Related Tags for htmlentities:


More Tutorials from this section

Ask Questions?    Discuss: htmlentities  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.