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 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 mb_ereg() Function The mb_ereg() function is an inbuilt function in PHP that is used for searching a string in the multibyte string by using the regular expression. Syntax: mb_ereg($pattern, $string, $matches ): bool Parameters: The following function has three parameters that are described below. $pattern: The regula 1 min read PHP mb_eregi() Function The mb_eregi() function is an inbuilt function in PHP that performs case-insensitive regular expression matches on a string having multibyte support. If the string pattern is matched, then it will return the string otherwise it will return false. Syntax: mb_eregi( string $pattern, string $string, ar 2 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 PHP mb_convert_case() Function The mb_convert_case() function is an inbuilt function in PHP that is used to perform case folding on the string and converted it into the specified mode of string. Syntax: string mb_convert_case( string $string, int $mode, string $encoding = null ) Parameters: This function accepts three parameters 2 min read PHP | base64_encode() Function The base64_encode() function is an inbuilt function in PHP that is used to encode data with MIME base64. MIME (Multipurpose Internet Mail Extensions) base64 is used to encode the string in base64. The base64_encoded data takes 33% more space than the original data. Syntax: string base64_encode( $dat 1 min read PHP | json_encode() Function The json_encode() function is an inbuilt function in PHP which is used to convert PHP array or object into JSON representation. Syntax : string json_encode( $value, $option, $depth ) Parameters: $value: It is a mandatory parameter which defines the value to be encoded. $option: It is optional parame 2 min read Like