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

php 中htmlentities導(dǎo)致中文無法查詢問題

 更新時間:2018年09月10日 11:11:33   作者:清茶咖啡  
php htmlentities用于接受一個字符串并將該字符串轉(zhuǎn)換為對應(yīng)的HTML實(shí)體,這篇文章主要介紹了php htmlentities導(dǎo)致中文無法查詢問題,,需要的朋友可以參考下

在php中htmlspecialchars, 將特殊字元轉(zhuǎn)成 HTML 格式,而htmlentities,將所有的字元都轉(zhuǎn)成 HTML 字串 了,下面我來分別簡單的介紹。

htmlentities用法

 $str = "John & 'Adams'"; 
 echo htmlentities($str, ENT_COMPAT); 
 echo " 
 "; 
 echo htmlentities($str, ENT_QUOTES); 
 echo " 
 "; 
 echo htmlentities($str, ENT_NOQUOTES); 
 ?> 
 
John & 'Adams'
 John & 'Adams'
 John & 'Adams'

瀏覽器輸出:

htmlspecialchars用法

& (和) 轉(zhuǎn)成 &
 " (雙引號) 轉(zhuǎn)成 "
 < (小于) 轉(zhuǎn)成 <
 > (大于) 轉(zhuǎn)成 >

$str = "John & 'Adams'"; 
 echo htmlspecialchars($str, ENT_COMPAT); 
 echo " 
 "; 
 echo htmlspecialchars($str, ENT_QUOTES); 
 echo " 
 "; 
 echo htmlspecialchars($str, ENT_NOQUOTES); 
 ?>  

他們的區(qū)別

這兩個函數(shù)的功能都是轉(zhuǎn)換字符為HTML字符編碼,特別是url和代碼字符串。防止字符標(biāo)記被瀏覽器執(zhí)行。使用中文時沒什么區(qū)別,但htmlentities會格式化中文字符使得中文輸入是亂碼

htmlentities轉(zhuǎn)換所有的html標(biāo)記,htmlspecialchars只格式化& ' " < 和 > 這幾個特殊符號

效果:

$str = '<a href="demo.php?m=index&a=index&name=中文" rel="external nofollow" rel="external nofollow" >測試頁面</a>';

echo 'htmlentities指定GB2312編碼:'.htmlentities($str,ENT_COMPAT,"GB2312").'';

echo 'htmlentities未指定編碼:'.htmlentities($str).'';

$str = '<a href="demo.php?m=index&a=index&name=中文" rel="external nofollow" rel="external nofollow" >測試頁面</a>';

echo htmlspecialchars($str).'';

總結(jié)

以上所述是小編給大家介紹的php 中htmlentities導(dǎo)致中文無法查詢問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論