1. About.com
  2. Computing & Technology
  3. PHP / MySQL

Discuss in my forum

Htmlspecialchars () PHP Function

By , About.com Guide

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 '>'

©2012 About.com. All rights reserved. 

A part of The New York Times Company.