Search code examples
phphtml-encode

How to encode special HTML characters in PHP


What is the easiest way to Html encode in PHP?


Solution

  • By encode, do you mean: Convert all applicable characters to HTML entities?

    htmlspecialchars or htmlentities

    You can also use strip_tags if you want to remove all HTML tags :

    strip_tags

    Note: this will NOT stop all XSS attacks