³¬Ô½PHP PHP¶¯Ì¬ | ¾­µäÎÄÕ | CLASS | Ïà¹ØÏÂÔØ | ³£¼ûÎÊÌâ | FORUM | WIKI | ÔÚÏßÊÖ²á
Site search:    
<html_entity_decodehtmlspecialchars>
Last updated: Fri, 22 Jun 2007

htmlentities

(PHP 3, PHP 4 , PHP 5)

htmlentities --  Convert all applicable characters to HTML entities

Description

string htmlentities ( string string [, int quote_style [, string charset]])

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.

Like htmlspecialchars(), the optional second quote_style parameter lets you define what will be done with 'single' and "double" quotes. It takes on one of three constants with the default being ENT_COMPAT:

±í¸ñ 1. Available quote_style constants

Constant NameDescription
ENT_COMPATWill convert double-quotes and leave single-quotes alone.
ENT_QUOTESWill convert both double and single quotes.
ENT_NOQUOTESWill leave both double and single quotes unconverted.

Support for the optional quote parameter was added in PHP 4.0.3.

Like htmlspecialchars(), it takes an optional third argument charset which defines character set used in conversion. Support for this argument was added in PHP 4.1.0. Presently, the ISO-8859-1 character set is used as the default.

PHP 4.3.0 ¼°ÆäºóÐø°æ±¾Ö§³ÖÈçÏÂ×Ö·û¼¯¡£

±í¸ñ 2. ÒÑÖ§³Ö×Ö·û¼¯

×Ö·û¼¯±ðÃûÃèÊö
ISO-8859-1ISO8859-1 Î÷Å·£¬Latin-1
ISO-8859-15ISO8859-15 Î÷Å·£¬Latin-9¡£Ôö¼ÓÁË Latin-1£¨ISO-8859-1£©ÖÐȱÉÙµÄÅ·Ôª·ûºÅ¡¢·¨¹ú¼°·ÒÀ¼×Öĸ¡£
UTF-8  ASCII ¼æÈݶà×Ö½Ú 8-bit Unicode¡£
cp866ibm866, 866 DOS-ÌØÓÐµÄ Cyrillic ×Öĸ×Ö·û¼¯¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
cp1251Windows-1251, win-1251, 1251 Windows-ÌØÓÐµÄ Cyrillic ×Öĸ×Ö·û¼¯¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
cp1252Windows-1252, 1252 Windows ¶ÔÓÚÎ÷Å·ÌØÓеÄ×Ö·û¼¯¡£
KOI8-Rkoi8-ru, koi8r ¶íÎÄ¡£PHP 4.3.2 ¿ªÊ¼Ö§³Ö¸Ã×Ö·û¼¯¡£
BIG5950 ·±ÌåÖÐÎÄ£¬Ö÷ÒªÓÃÓÚÖйų́Íå¡£
GB2312936 ¼òÌåÖÐÎÄ£¬¹ú¼Ê±ê×¼×Ö·û¼¯¡£
BIG5-HKSCS  ·±ÌåÖÐÎÄ£¬Big5 µÄÑÓÉ죬Ö÷ÒªÓÃÓÚÏã¸Û¡£
Shift_JISSJIS, 932 ÈÕÎÄ¡£
EUC-JPEUCJP ÈÕÎÄ¡£

×¢: ISO-8859-1 ½«´úÌæÈÎºÎÆäËüÎÞ·¨Ê¶±ðµÄ×Ö·û¼¯¡£

If you're wanting to decode instead (the reverse) you can use html_entity_decode().

Àý×Ó 1. A htmlentities() example

<?php
$str
= "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

See also html_entity_decode(), get_html_translation_table(), htmlspecialchars(), nl2br(), and urlencode().




add a note add a note User Contributed Notes
htmlentities
kumar at chicagomodular.com
29-Oct-2002 09:51
without heavy scientific analysis, this seems to work as a quick fix to making text originating from a Microsoft Word document display as HTML:

function DoHTMLEntities ($string)
{
$trans_tbl = get_html_translation_table (HTML_ENTITIES);

// MS Word strangeness..
// smart single/ double quotes:
$trans_tbl[chr(145)] = '\'';
$trans_tbl[chr(146)] = '\'';
$trans_tbl[chr(147)] = '&quot;';
$trans_tbl[chr(148)] = '&quot;';
// é :
$trans_tbl[chr(142)] = '&eacute;';

return strtr ($string, $trans_tbl);
}

<html_entity_decodehtmlspecialchars>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22