Navigation:    Home arrow Escape HTML Characters
Escape HTML Characters PDF  
Digg Reddit Ma.gnolia Stumble Upon Facebook Twitter Google Yahoo! MyWeb Furl" BlinkList Technorati Mixx Bookmark
Article Index
Escape HTML Characters
Page 2

htmlspecialchars() function

 Is very much like htmlentities() function. Unlike this function, it does not convert all applicable characters to HTML entities, but only some of them:

    - '&' (ampersand) becomes '&'

    - '"' (double quote) becomes '"' when ENT_NOQUOTES is not set.

    - ''' (single quote) becomes ''' only when ENT_QUOTES is set.

    - '<' (less than) becomes '<'

    - '>' (greater than) becomes '>'

 Otherwise, functions parameters are the same: string htmlspecialchars ( string $string [, int $quote_style [, string $charset]] );

To see the difference between these two functions I will show you an example:

 The simple text:

<b>Confirmar contraseña</b>

for htmlentities() function will output:

 &lt;b&gt;Confirmar contrase&ntilde;a&lt;/b&gt;

and for htmlspecialchars() function will output:

 &lt;b&gt;Confirmar contraseña&lt;/b&gt;

See the difference? For the first function, the special Spanish character ñ is translated also, while for the second is left unchanged.