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.

Syntax

array|string mb_http_input(str $type=null)

Parameters

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.

Example

<?php
   // It will return the input character encoding
   //UTF-8
   $string =mb_http_input("I");
   var_dump($string);
?>

Output

array(1) {
   [0]=>
   string(5) "UTF-8"
}

Updated on: 11-Oct-2021

420 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements