PHP – Retrieve internal configuration variables of iconv extension using iconv_get_encoding() function

PHPServer Side ProgrammingProgramming

In PHP, the iconv_get_encoding() function is used to retrieve the internal configuration variables of iconv extension. This function is an inbuilt PHP function which is being used from PHP 4 version.


mixed iconv_get_encoding($type = "all")


The iconv_get_encoding() function is used only single parameter $type.

$type − The values of the optional type parameter can be

  • all
  • input_encoding
  • output_encoding
  • internal_encoding

Return Value

The iconv_get_encoding() function returns the current value of the internal configuration variable if successful or it returns False on failure. If the type is not present or set to all, then iconv_get_encoding() returns an array that stores all these variables.

Example 1

 Live Demo

      iconv_set_encoding("internal_encoding", "UTF-8");
      iconv_set_encoding("output_encoding", "ISO-8859-1");


array(3) {
   string(5) "UTF-8"
   string(10) "ISO-8859-1"
   string(5) "UTF-8"

Explanation - The above PHP program will print all the encoding (internal encoding, output encoding) because iconv_get_encoding() is set to all. 

Example 2 - Using only internal_encoding

 Live Demo

   // Using only internal encoding
   iconv_set_encoding("internal_encoding", "UTF-8");


string(5) "UTF-8"
Updated on 21-Aug-2021 07:41:51