Today talk about coding garbled problem, when a page exists two kinds of code, no matter how you choose the first choice will appear garbled, the solution:
1. What you are coding on the Web page.
2. First determine if the string encoding is UTF8 code as follows:
PHP code
function Is_utf8 ($word)
{
if (Preg_match ("/^ ([". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {1}/", $word) = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {1}$/", $word) = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {2,}/", $word) = = True)
{
return true;
}
Else
{
return false;
}
}
3. Convert to gb2312, use the conversion function iconv;
PHP code
if (Is_utf8 ($tit) ==1)
$tit = Iconv ("Utf-8", "GBK", $tit);
May investors do something "octopus investment Banking": http://licai.daiyuline.com/caijingxinwen/335.html
May Open prev Rose 1.85% "Securities Investment": http://licai.daiyuline.com/zhengquan/334.html
PHP determines if string encoding is UTF8 and conversion issues