HomeCoding & Programming

Difference between htmlspecialchars and htmlentities

Like Tweet Pin it Share Share Email

What is the difference between htmlspecialchars and htmlentities PHP functions?

 

htmlentities:

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

 

htmlspecialchars:
Some characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made.If you require all HTML character entities to be translated, use htmlentities() instead.

 

1. htmlspecialchars may be used when there is no need to encode all characters which have their HTML equivalents.

 

2. htmlspecialchars only takes care of <, >, single quote ‘, double quote ” and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

 

In Short, you can say

 

htmlspecialchars(): Convert some special characters to HTML entities (Only the most widely used)

htmlentities(): Convert ALL special characters to HTML entities

 

 

Comments (1)

  • It is very helpful to understanding the programming concepts for php language

Comments are closed.