PHP htmlentities vs htmlspecialchars differences php functions

RegisterLogin
PHP htmlentities vs htmlspecialchars differences php functions
Post Description: PHP htmlentities vs htmlspecialchars differences php functions
Tags: PHP, htmlentities, vs, htmlspecialchars, differences, php, functions
This Post Was Posted On Feb 29, 2008 By web hosting #1303
so what is the difference between htmlspecialchars() and htmlentities?


htmlspecialchars � Convert special characters to HTML entities


htmlentities � Convert all applicable characters to HTML entities



htmlentities

PHP CODE:
<?php
$str = "A 'quote' is <b>bold</b>";

echo htmlentities($str);
echo htmlentities($str, ENT_QUOTES);
?>

OUTPUT
A 'quote' is &lt;b&gt;bold&lt;/b&gt;

A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;


htmlspecialchars

PHP CODE:
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; //
?>

OUTPUT
&lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;


Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
©2011 Webune Forums - Tue Dec 20, 2011 1:54 am
Powered by: Webune Forums V3