html实体转化字符串 php_PHP htmlentities() 函数
更多實例
例子 1
把字符轉換為 HTML 實體:
$str = "Bill & 'Steve'";
echo htmlentities($str, ENT_COMPAT); // 只轉換雙引號
echo "
";
echo htmlentities($str, ENT_QUOTES); // 轉換雙引號和單引號
echo "
";
echo htmlentities($str, ENT_NOQUOTES); // 不轉換任何引號
?>
以上代碼的 HTML 輸出如下(查看源代碼):
Bill & 'Steve'
Bill & 'Tarzan'
Bill & 'Steve'
以上代碼的瀏覽器輸出:
Bill & 'Steve'
Bill & 'Steve'
Bill & 'Steve'
例子 2
通過使用西歐字符集,把一些字符轉換為 HTML 實體:
$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 輸出如下(查看源代碼):
My name is ?yvind ?sane. I'm Norwegian.
以上代碼的瀏覽器輸出:
My name is ?yvind ?sane. I'm Norwegian.
總結
以上是生活随笔為你收集整理的html实体转化字符串 php_PHP htmlentities() 函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 比华为更强!魅族20 INFINITY的
- 下一篇: 真芭比Q了!维珍轨道宣布将裁员90% 很