PHP mb_detect_encoding() Function Last Updated : 26 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The mb_detect_encoding() is an inbuilt function in PHP that is used to detect the encoding of the string. Syntax: string|false mb_detect_encoding( string $string, array|string|null $encodings = null, bool $strict = false ) Parameters: This function accepts three parameters that are described below. $string: The string for which the encoding needs to be detected.$encoding: A comma-separated list of encodings to be checked. If not specified, a list of popular encodings is used.$strict: A boolean value indicating whether to use strict detection or not. If set to "true", only encodings that are super-sets of the input string's encoding are returned. Return Values: This function returns detecting encoding of the input string, if no encoded is detected, it will return "false". Example 1: The following program demonstrates the mb_detect_encoding() function. PHP <?php $string = "Hello world!"; $encoding = mb_detect_encoding($string); echo "The string '$string' is encoded in '$encoding'."; ?> Output: The string 'Hello world!' is encoded in 'ASCII'. Example 2: The following program demonstrates the mb_detect_encoding() function. PHP <?php $string = "This is an English sentence."; $encoding = mb_detect_encoding($string); if ($encoding === 'UTF-8') { echo "The string '$string' is encoded in UTF-8."; } else { echo "The string '$string' is not encoded in UTF-8."; } ?> Output: The string 'This is an English sentence.' is not encoded in UTF-8. Reference: https://www.php.net/manual/en/function.mb-detect-encoding.php Comment More infoAdvertise with us Next Article PHP mb_detect_encoding() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Multibyte-String Similar Reads PHP mb_check_encoding() Function The mb_check_encoding() function is an inbuilt function in PHP that is used to check whether a given string is valid for specified encoding or not. Syntax: bool mb_check_encoding( array|string|null $value = null, string $encoding = null ) Parameters: This function accepts two parameters that are des 2 min read PHP mb_convert_encoding() Function The mb_convert_encoding() function is an inbuilt function in PHP that transforms the string into another character encoding. Syntax: mb_convert_encoding( array|string $string, string $to_encoding, array|string|null $from_encoding = null ): array|string|falseParameters: This function has 3 parameters 1 min read PHP mb_encoding_aliases() Function The mb_encoding_aliases() is an inbuilt PHP function that can be utilized to retrieve aliases for a known encoding type. Syntax: mb_encoding_aliases(string $encoding): array Parameter: This function has only one parameter: encoding: This parameter specifies the encoding type that is to be checked fo 1 min read PHP mb_detect_order() Function The mb_detect_order() function is an inbuilt function in PHP that is utilized to set or get the character encoding detection order. Syntax: mb_detect_order(array|string|null $encoding = null): array|bool Parameters: Â This function has only one parameter. encoding: This parameter returns the current 1 min read PHP | iconv_get_encoding() Function The iconv_get_encoding() function is an inbuilt function in PHP which is used to retrieve the internal configuration variables of iconv extension. Syntax: mixed iconv_get_encoding( $type = "all" ) Parameters: This function accepts single parameter $type. The value of $type parameter are: all input_e 1 min read Like