php采用get獲取url漢字出現(xiàn)亂碼的解決辦法:使用函數(shù)【string urlencode (string $str)】,將字符串編碼并將其用于url的請(qǐng)求部分,代碼為【echo '<a href="mycgi?foo=', url】。
php采用get獲取url漢字出現(xiàn)亂碼的解決辦法:
1、使用:
代碼如下:
<a href="list.php?plate=<?php echo urlencode("轄區(qū)動(dòng)態(tài)");?>" charset="utf-8" target="main">[查看]</a>然后在list.php頁(yè)面這樣用
代碼如下:
<?phpheader("content-type: text/html; charset=utf-8");if($_get['plate'])echo $plate=urldecode($_get['plate']);?>也就不會(huì)亂碼和傳遞不正常了。
注意此處的接收get頁(yè)面編碼需要和發(fā)送端一致!
2、關(guān)于string urlencode ( string $str )函數(shù)
此函數(shù)便于將字符串編碼并將其用于 url 的請(qǐng)求部分,同時(shí)它還便于將變量傳遞給下一頁(yè)。
示例1 urlencode()
代碼如下:
<?phpecho '<a href="mycgi?foo=', urlencode($userinput), '">';?>示例2 urlencode() 與 htmlentities()
代碼如下:
<?php$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);echo '<a href="mycgi?' . htmlentities($query_string) . '">';?>相關(guān)學(xué)習(xí)推薦:php編程(視頻)