PHP –– htmlentities
written by: admin
Date Written: 4/16/10
Last Updated: 4/19/10
htmlentities is a way of converting html characters into it's html entities.
For example
<script type="text/javascript">
window.location = "http://www.sovereigngraceopc.org/"
</script>
can be converted using
htmlentities into:
<script type="text/javascript"> window.location = "http://www.sovereigngraceopc.org/"> </script>
When echoed into a textarea or as text the string will look like:
<script type="text/javascript">
window.location = "http://www.sovereigngraceopc.org/"
</script>
but the code will not execute.
When to use
It is handy for
displaying code or
disabling user submitted code so as to avoid possible malicious code by an unfriendly visitor.
To echo the code as:
<script type="text/javascript"> window.location = "http://www.sovereigngraceopc.org/"> </script>
you will need to use the following:
<?php
$string=htmlentities($string);
$string=htmlentities($string);
echo "$string";
?>
or
<?php
echo htmlentities(htmlentities($string));
?>
You can try out the script
here.
TAGS: php