PHP html_entity_decode() 函數
實例
把 HTML 實體轉換為字符:
?php
$str = "lt;copy; W3CSccedil;hdeg;deg;brvbar;sect;gt;";
echo html_entity_decode($str);
?>
上面代碼的 HTML 輸出如下(查看源代碼):
!DOCTYPE html>
html>
body>
© W3CSçh°°¦§>
/body>
/html>
上面代碼的瀏覽器輸出如下:
© W3CSçh°°¦§>
定義和用法
html_entity_decode() 函數把 HTML 實體轉換為字符。
html_entity_decode() 函數是htmlentities()
函數的反函數。
語法
html_entity_decode( _string,flags,character-se_ t)


實例 1
把一些 HTML 實體轉換為字符:
?php
$str = "Jane #039;Tarzan#039;";
echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double and single
quotes
echo "br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
上面代碼的 HTML 輸出如下(查看源代碼):
!DOCTYPE html>
html>
body>
Jane #039;Tarzan#039;br>
Jane 'Tarzan'br>
Jane #039;Tarzan#039;
/body>
/html>
上面代碼的瀏覽器輸出如下:
Jane 'Tarzan'
Jane 'Tarzan'
Jane 'Tarzan'
實例 2
通過使用西歐字符集,把一些 HTML 實體轉換為字符:
?php
$str = "My name is Oslash;yvind Aring;sane. I#039;m Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "ISO-8859-1");
?>
The HTML output of the code above will be (View Source):
!DOCTYPE html>
html>
body>
My name is Øyvind Åsane. I'm Norwegian.
/body>
/html>
上面代碼的瀏覽器輸出如下:
My name is Øyvind Åsane. I'm Norwegian.
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
您可能感興趣的文章:- PHP微信發送推送消息亂碼的解決方法
- PHP刪除數組中特定元素的兩種方法
- PHP實時統計中文字數和區別
- PHP正則判斷一個變量是否為正整數的方法
- PHP正則驗證字符串是否為數字的兩種方法并附常用正則
- PHP判斷是否是微信打開還是瀏覽器打開的方法
- asp函數split()對應php函數explode()
- PHP htmlentities()函數用法講解
- PHP hex2bin()函數用法講解
- PHP中rename()函數的妙用講解