▼  Site Navigation Main Articles News Search  ▼  Anime + Manga Anime Reviews Anime Characters Gallery Screenshots Manga Reviews  ▼  Misc Links to Webcomics Bible Quotes About Older Musings
site version 7.3
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:

&lt;script type=&quot;text/javascript&quot;&gt; window.location = &quot;http://www.sovereigngraceopc.org/&quot; &lt;/script&gt;

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:

&lt;script type=&quot;text/javascript&quot;&gt; window.location = &quot;http://www.sovereigngraceopc.org/&quot; &lt;/script&gt;

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
copyright 2005–2024