(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_detect_encoding — Detect character encoding
mb_detect_encoding ( string $string [, array|string|null $encodings = null [, bool $strict = false ]] ) : string|false
Detects character encoding in string string
.
string
The string being detected.
encodings
encodings
is list of character encoding. Encoding order may be specified by array or comma separated list string.
If encodings
is omitted or null
, detect_order is used.
strict
strict
specifies whether to use the strict encoding detection or not. Default is false
.
The detected character encoding or false
if the encoding cannot be detected from the given string.
Example #1 mb_detect_encoding() example
<?php /* Detect character encoding with current detect_order */ echo mb_detect_encoding($str); /* "auto" is expanded according to mbstring.language */ echo mb_detect_encoding($str, "auto"); /* Specify "encodings" parameter by list separated by comma */ echo mb_detect_encoding($str, "JIS, eucjp-win, sjis-win"); /* Use array to specify "encodings" parameter */ $ary[] = "ASCII"; $ary[] = "JIS"; $ary[] = "EUC-JP"; echo mb_detect_encoding($str, $ary); ?>
© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.mb-detect-encoding.php