About PHP string garbled problem, when a page exists in two kinds of code, no matter how you choose the first choice will appear garbled, then how to solve this problem? Fire small to provide you with the method:
One. First of all, according to international practice, check your file encoding and database, page encoding is consistent.
Two. If the "one" is not a problem, then you need to judge the encoding of the string, we just have to judge a kind of can, about the detection is UTF8 coding problem, help the home has published related articles, but not very good, today found on the Internet a more perfect function, the code is as follows:
Copy to ClipboardWhat to refer to: [www.bkjia.com]function Is_utf8 ($liehuo _net)
{
if (Preg_match ("/^ ([". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {1}/", $liehuo _net) = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {1}$/", $liehuo _net) = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." {1} [". chr (128)." -". Chr (191)." {1} [". chr (128)." -". Chr (191)." {1}) {2,}/", $liehuo _net) = = True)
{
return true;
}
Else
{
return false;
}
}
Now for the use of the method, the master will not have to look, because some beginners do not know how to introduce and use this function, the bottom is the method.
One. Save the above code as a standalone file, for example: liehuo_func_validt.php, save to the Web site root directory, and then introduce to the file, add the following code:
Copy to ClipboardWhat to refer to: [www.bkjia.com]Require ("liehuo_func_validt.php");
Next, judge the code, and write it down below the code:
Copy to ClipboardWhat to refer to: [www.bkjia.com]if (Is_utf8 ($liehuo) ==1)
{
$liehuo = Iconv ("Utf-8", "GBK", $liehuo);
}
That's all you can do.
Two. Put the judgment function directly at the top of the file to use, and then add the judgment code, more verbose, haha. More attention to help the home, support liehuo.net Oh.
http://www.bkjia.com/PHPjc/364702.html www.bkjia.com true http://www.bkjia.com/PHPjc/364702.html techarticle about PHP string garbled problem, when a page exists in two kinds of code, no matter how you choose the first choice will appear garbled, then how to solve this problem? A small part of the fire.