Home >Backend Development >PHP Tutorial >How does php read the encoding of text?

How does php read the encoding of text?

怪我咯
怪我咯Original
2017-07-06 10:52:082062browse

This article mainly introduces the relevant information about the encoding of PHP detection text. Friends who need it can refer to it

Judge whether it belongs to the encoding by a loop encoding of the text. .

public function chkCode($string) {
    $code = array(
      'ASCII',
      'GBK',
      'UTF-8'
    );
    foreach ($code as $c) {
      if ($string === iconv('UTF-8', $c, iconv($c, 'UTF-8', $string))) {
        return $c;
      }
    }
    return null;
  }

The above is the detailed content of How does php read the encoding of text?. 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