Home>Article>Backend Development> How to convert php string to utf8

How to convert php string to utf8

藏色散人
藏色散人 Original
2020-10-09 09:59:25 3274browse

How to convert php string to utf8: First create a PHP sample file; then define a "strToUtf8" method; finally implement encoding conversion through functions such as "mb_detect_encoding".

How to convert php string to utf8

Recommended: "PHP Video Tutorial"

php converts character encoding to utf-8

function strToUtf8($str){ $encode = mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5')); if($encode == 'UTF-8'){ return $str; }else{ return mb_convert_encoding($str, 'UTF-8', $encode); } }

The above is the detailed content of How to convert php string to utf8. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn