Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html encode in PHP

What is the easiest way to Html encode in PHP?

like image 577
Mathias F Avatar asked Dec 09 '09 13:12

Mathias F


People also ask

How can I encode HTML code 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().

What is the use of HTML entities () function in PHP?

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.

What does Htmlspecialchars do in PHP?

The htmlspecialchars() function converts some predefined characters to HTML entities.


1 Answers

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

like image 190
Vallières Avatar answered Sep 29 '22 09:09

Vallières