Search notes:

PHP code snippets: the htmlspecialchars function

htmlspecialchars converts characters that have a meaning in HTML to HTML character entities.
For example, a & is turned into a &amp;, or a < into a &lt;.
<html><head><title>htmlspecialchars</title></head>
<body>

  <?php 
   

    $html_snippet = "Now, for <i>something</i> very <b>bold</b>!";

    echo '$html_snippet: ' . $html_snippet . "<br>";
    echo 'htmlspecialchars($html_snippet): ' . htmlspecialchars($html_snippet) . "<br>";


  ?>

  <p>See also <a href='strip_tags.html'>strip_tags.html</a> and <a href='form_handling.html'>form_handling.html</a>.
    
</body>
</html>
Github repository about-php, path: /htmlspecialchars.html

See also

Compare with
Other PHP snippets.

Index