How to remove HTML special characters from a string in PHP?

How to remove HTML special characters from a string in PHP?

Asked on November 1, 2018 in PHP.
Add Comment


  • 1 Answer(s)

    PHP htmlspecialchars() function is used.
    Certain characters such as (&, “, ‘, <, >) have special significance in HTML, and should be converted to HTML entities.
    The PHP htmlspecialchars() function is used to convert special characters in a string to HTML entities.

    For example:

    <?php
    $my_str = "String with <b>special</b> characters.";
     
    // Removing HTML special characters
    echo htmlspecialchars($my_str);
    ?>
    

     

    Answered on November 1, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.