How to convert php string to utf8 encoding: first use the "mb_detect_encoding" method to automatically identify the string encoding; then use the "mb_convert_encoding" function to convert it into the international standard encoding "utf-8".
Recommended: "PHP Video Tutorial"
When using mb_convert_encoding, you must first know the character encoding. If the encoding is wrong It will be garbled. Use mb_detect_encoding to automatically identify the string encoding and convert it to the international standard encoding utf-8 encoding.
<?php $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5','LATIN1')); if($encode != 'UTF-8'){ $name = mb_convert_encoding($name, 'UTF-8', $encode); }
mb_convert_encoding — Convert character encoding
mb_detect_encoding — Detect character encoding
The above is the detailed content of How to convert php string to utf8 encoding. For more information, please follow other related articles on the PHP Chinese website!