What’s the difference between htmlentities() and htmlspecialchars()?

April 11, 2010 | Filed Under PHP | Comments Off

htmlentities — Convert all applicable characters to HTML entities

<?php
$str
= "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities style="color: #007700;">($str, ENT_QUOTES);
?>
htmlspecialchars much  should i take — Convert special characters to HTML entities
<?php
$new
= htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo
$new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
?>

Comments

Comments are closed.

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker