WHAT’S THE DIFFERENCE BETWEEN HTMLENTITIES() AND HTMLSPECIALCHARS()?

Sanjay Sharma

Total Post:42

Points:210
Posted by  Sanjay Sharma
PHP 
PHP
 1127  View(s)
Ratings:
Rate this:
  1. Sanjay Sharma

    Post:42

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


    Difference between htmlentities() and htmlspecialchars()

    htmlentities

    PHP CODE:
    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;

      Modified On Apr-04-2016 01:21:28 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!