首頁  >  文章  >  php教程  >  php htmlentities()函數的定義和用法

php htmlentities()函數的定義和用法

高洛峰
高洛峰原創
2017-01-03 14:12:501301瀏覽

php htmlentities() 函數把字元轉換為 HTML 實體,本文章向碼農介紹php htmlentities() 函數基本使用方法和實例介紹,需要的碼農可以參考一下。

定義和用法

htmlentities() 函數把字元轉換為 HTML 實體。

提示:要把 HTML 實體轉換回字符,請使用 html_entity_decode() 函數。

提示:請使用 get_html_translation_table() 函數來傳回 htmlentities() 使用的翻譯表。

語法

htmlentities(string,flags,character-set,double_encode) 

php htmlentities()函数的定义和用法

技術細節

php htmlentities()函数的定义和用法 範例

技術細節

 

以上程式碼的HTML 輸出如下(查看原始碼):

<?php
$str = "Bill & &#39;Steve&#39;";
echo htmlentities($str, ENT_COMPAT); // 只转换双引号
echo "<br>";
echo htmlentities($str, ENT_QUOTES); // 转换双引号和单引号
echo "<br>";
echo htmlentities($str, ENT_NOQUOTES); // 不转换任何引号
?>

   

以上代碼的瀏覽器輸出:

<!DOCTYPE html>
<html>
<body>
Bill & &#39;Steve&#39;<br>
Bill & &#39;Tarzan&#39;<br>
Bill & &#39;Steve&#39;
</body>
</html>

   

Bill & &#39;Steve&#39;
Bill & &#39;Steve&#39;
Bill & &#39;Steve&#39;

   

以上程式碼的HTML 輸出如下(檢視原始碼):

<?php
$str = "My name is ?yvind ?sane. I&#39;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
?>

   

.

以上這篇php htmlentities()函數的定義和用法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持PHP中文網。

更多php htmlentities()函數的定義和用法相關文章請關注PHP中文網!


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn