How does php read the encoding of text?

怪我咯
Release: 2023-03-12 21:38:02
Original
2054 people have browsed it

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;
  }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template