PHP html_entity_decode() º¯Êý
ʵÀý
°Ñ HTML ʵÌåת»»Îª×Ö·û£º
<?php $str = "<© W3Sçh°°¦§>"; echo html_entity_decode($str); ?>
ÒÔÉÏ´úÂëµÄ HTML Êä³öÈçÏ£¨²é¿´Ô´´úÂ룩£º
<!DOCTYPE html> <html> <body> <? W3S?h????> </body> </html>
ÒÔÉÏ´úÂëµÄä¯ÀÀÆ÷Êä³ö£º
<? W3S?h????>
¶¨ÒåºÍÓ÷¨
html_entity_decode() º¯Êý°Ñ HTML ʵÌåת»»Îª×Ö·û¡£
html_entity_decode() º¯ÊýÊÇ htmlentities() º¯ÊýµÄ·´º¯Êý¡£
Óï·¨
html_entity_decode(string,flags,character-set)
| ²ÎÊý | ÃèÊö |
|---|---|
| string | ±ØÐè¡£¹æ¶¨Òª½âÂëµÄ×Ö·û´®¡£ |
| flags |
¿ÉÑ¡¡£¹æ¶¨ÈçºÎ´¦ÀíÒýºÅÒÔ¼°Ê¹ÓÃÄÄÖÖÎĵµÀàÐÍ¡£ ¿ÉÓõÄÒýºÅÀàÐÍ£º
¹æ¶¨ËùʹÓÃÎĵµÀàÐ͵ĸ½¼Ó flags£º
|
| character-set |
¿ÉÑ¡¡£×Ö·û´®Öµ£¬¹æ¶¨ÒªÊ¹ÓõÄ×Ö·û¼¯¡£ ÔÊÐíµÄÖµ£º
×¢ÊÍ£ºÔÚ PHP 5.4 ֮ǰµÄ°æ±¾£¬ÎÞ·¨±»Ê¶±ðµÄ×Ö·û¼¯½«±»ºöÂÔ²¢ÓÉ ISO-8859-1 Ìæ´ú¡£×Ô PHP 5.4 Æð£¬ÎÞ·¨±»Ê¶±ðµÄ×Ö·û¼¯½«±»ºöÂÔ²¢ÓÉ UTF-8 Ìæ´ú¡£ |
¼¼Êõϸ½Ú
| ·µ»ØÖµ£º | ·µ»Ø±»×ª»»µÄ×Ö·û´® |
| PHP °æ±¾£º | 4.3.0+ |
¸üÐÂÈÕÖ¾£º
| °æ±¾ | ˵Ã÷ |
|---|---|
| PHP 5 | character-set ²ÎÊýµÄĬÈÏÖµ¸ÄΪ UTF-8¡£ |
| PHP 5.4 |
ÐÂÔöÁËÓÃÓڹ涨·Òë±íÊÊÓõÄÎĵµÀàÐ͵ĸ½¼Ó flags£º
|
| PHP 5.3.4 | ÐÂÔöÁ˶Զà×Ö½Ú±àÂëµÄÖ§³Ö¡£ |
¸ü¶àʵÀý
Àý×Ó 1
°Ñ HTML ʵÌåת»»Îª×Ö·û£º
<?php $str = "Bill & 'Steve'"; echo html_entity_decode($str, ENT_COMPAT); // ֻת»»Ë«ÒýºÅ echo "<br>"; echo html_entity_decode($str, ENT_QUOTES); // ת»»Ë«ÒýºÅºÍµ¥ÒýºÅ echo "<br>"; echo html_entity_decode($str, ENT_NOQUOTES); // ²»×ª»»ÈκÎÒýºÅ ?>
ÒÔÉÏ´úÂëµÄ HTML Êä³ö£¨²é¿´Ô´´úÂ룩£º
<!DOCTYPE html> <html> <body> Bill & 'Steve'<br> Bill & 'Steve'<br> Bill & 'Steve' </body> </html>
ÒÔÉÏ´úÂëµÄä¯ÀÀÆ÷Êä³ö£º
Bill & 'Steve' Bill & 'Steve' Bill & 'Steve'
Àý×Ó 2
ͨ¹ýʹÓÃÎ÷Å·×Ö·û¼¯£¬°Ñ HTML ʵÌåת»»Îª×Ö·û£º
<?php $str = "My name is Øyvind Åsane. I'm Norwegian."; echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1"); ?>
ÒÔÉÏ´úÂëµÄ HTML Êä³ö£¨²é¿´Ô´´úÂ룩£º
<!DOCTYPE html> <html> <body> My name is ?yvind ?sane. I'm Norwegian. </body> </html>
ÒÔÉÏ´úÂëµÄä¯ÀÀÆ÷Êä³ö£º
My name is ?yvind ?sane. I'm Norwegian.