How to query the encoding of a variable in php

藏色散人
Release: 2023-03-14 17:14:01
Original
2634 people have browsed it

In PHP, you can query the encoding of variables through the mb_detect_encoding function. The function of this function is to detect the encoding of characters. Its usage syntax is "mb_detect_encoding(string $str, mixed $encoding_list...)".

How to query the encoding of a variable in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to query the encoding of variables in php?

mb_detect_encoding

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_detect_encoding — Detect characters Encoding

Description

mb_detect_encoding(string $str, mixed $encoding_list = mb_detect_order(), bool $strict = false): string
Copy after login

Detect the encoding of the string str.

Parameters

str

The string to be checked.

encoding_list

encoding_list is a character encoding list. The encoding order can be specified by an array or a comma-separated list of strings.

If encoding_list is omitted, detect_order will be used.

strict

strict specifies whether to strictly detect encoding. The default is false.

Return value

The detected character encoding, or false is returned when the encoding of the specified string cannot be detected.

Example

Example#1 mb_detect_encoding() Example

<?php
/* 使用当前的 detect_order 来检测字符编码 */
echo mb_detect_encoding($str);
/* "auto" 将根据 mbstring.language 来扩展 */
echo mb_detect_encoding($str, "auto");
/* 通过逗号分隔的列表来指定编码列表 encoding_list */
echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win");
/* 使用数组来指定编码列表 encoding_list  */
$ary[] = "ASCII";
$ary[] = "JIS";
$ary[] = "EUC-JP";
echo mb_detect_encoding($str, $ary);
?>
Copy after login

See

mb_detect_order() - Set/get the detection order of character encoding

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to query the encoding of a variable in php. 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