1. Home
  2. Computing & Technology
  3. PHP / MySQL

Htmlspecialchars () PHP Function

By Angela Bradley, About.com

Definition: Htmlspecialchars () is used to convert special characters to HTML entities so their meanings are preserved. It will return the altered string. It is phrased as: htmlspecialchars ( string, quote_style ,charset ). Both quote_stype and charset are optional, and do not need to be included.
Also Known As: HTML Special Characters
Examples:
<?php
$convert = htmlspecialchars("<a href='http://www.mysite.com'>Links</a>");
echo $convert;
?>
Replacements
'&' (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 '>'
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. htmlspecialchars - HTML in PHP - Htmlspecialchars PHP

©2009 About.com, a part of The New York Times Company.

All rights reserved.