欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP htmlentities()函數(shù)用法講解

 更新時(shí)間:2019年02月25日 16:42:43   作者:php參考手冊(cè)  
今天小編就為大家分享一篇關(guān)于PHP htmlentities()函數(shù)用法講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧

PHP htmlentities() 函數(shù)

實(shí)例

把一些字符轉(zhuǎn)換為 HTML 實(shí)體:

<?php 
$str = "<© W3CSçh°°¦§>"; 
echo htmlentities($str); 
?>

上面代碼的 HTML 輸出如下(查看源代碼):

<!DOCTYPE html> 
<html> 
<body> 
&lt;&copy; W3CS&ccedil;h&deg;&deg;&brvbar;&sect;&gt; 
</body> 
</html>

上面代碼的瀏覽器輸出如下:

<© W3CSçh°°¦§>

定義和用法

htmlentities()函數(shù)把字符轉(zhuǎn)換為 HTML 實(shí)體。

提示: 要把 HTML 實(shí)體轉(zhuǎn)換回字符,請(qǐng)使用 html_entity_decode() 函數(shù)。

提示: 請(qǐng)使用 get_html_translation_table() 函數(shù)來(lái)返回 htmlentities() 使用的翻譯表。

語(yǔ)法

htmlentities( _string,flags,character-set,double_encode_ )

實(shí)例 1

把一些字符轉(zhuǎn)換為 HTML 實(shí)體:

<?php 
$str = "Jane & 'Tarzan'"; 
echo htmlentities($str, ENT_COMPAT); // Will only convert double quotes 
echo "<br>"; 
echo htmlentities($str, ENT_QUOTES); // Converts double and single quotes 
echo "<br>"; 
echo htmlentities($str, ENT_NOQUOTES); // Does not convert any quotes 
?>

上面代碼的 HTML 輸出如下(查看源代碼):

<!DOCTYPE html> 
<html> 
<body> 
Jane &amp; 'Tarzan'<br> 
Jane &amp; &#039;Tarzan&#039;<br> 
Jane &amp; 'Tarzan' 
</body> 
</html>

上面代碼的瀏覽器輸出如下:

Jane & 'Tarzan' 
Jane & 'Tarzan' 
Jane & 'Tarzan'

實(shí)例 2

通過(guò)使用西歐字符集,把一些字符轉(zhuǎn)換為 HTML 實(shí)體:

<?php 
$str = "My name is Øyvind Åsane. I'm Norwegian."; 
echo htmlentities($str, ENT_QUOTES, "ISO-8859-1"); // Will only convert double
quotes (not single quotes), and uses the character-set Western European 
?>

上面代碼的 HTML 輸出如下(查看源代碼):

<!DOCTYPE html> 
<html> 
<body> 
My name is &Oslash;yvind &Aring;sane. I&#039;m Norwegian. 
</body> 
</html>

上面代碼的瀏覽器輸出如下:

My name is Øyvind Åsane. I'm Norwegian.

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

最新評(píng)論