What is the easiest way to Html encode in PHP?
The htmlentities() function converts characters to HTML entities. Tip: To convert HTML entities back to characters, use the html_entity_decode() function. Tip: Use the get_html_translation_table() function to return the translation table used by htmlentities().
htmlentities() Function: The htmlentities() function is an inbuilt function in PHP that is used to transform all characters which are applicable to HTML entities. This function converts all characters that are applicable to HTML entities.
The htmlspecialchars() function converts some predefined characters to HTML entities.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With