Home  >  Article  >  Backend Development  >  How to query the encoding of a variable in php

How to query the encoding of a variable in php

藏色散人
藏色散人Original
2021-12-31 10:32:142462browse

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

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

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!

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