PHP – Detect HTTP input character encoding with mb_http_input()

The mb_http_input() function in PHP is used to detect the HTTP (Hyper-text transfer protocols) input character encoding. This function is supported in PHP 5.4 or higher version.


array|string mb_http_input(str $type=null)


mb_http_input() accepts only a single parameter −

  • $type − In the type parameter, the input string specifies the input type, like −

    • G is used for GET,

    • P is used for POST,

    • C is used for COOKIE,

    • S is used for STRING,

    • L is used for LIST, and

    • I for the whole list (it will return array).

If the type is omitted, then it returns the last input type processed.

Return Values

mb_http_input() returns the character encoding name as per the type, or an array of character encoding names. If the type is "I" and if the mb_http_input() does not process the specified HTTP input, then it returns False.


   // It will return the input character encoding
   $string =mb_http_input("I");


array(1) {
   string(5) "UTF-8"