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.

Syntax

mixed iconv_get_encoding($type = "all")

Parameter

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

<pre>
   <?php
      iconv_set_encoding("internal_encoding", "UTF-8");
      iconv_set_encoding("output_encoding", "ISO-8859-1");
      var_dump(iconv_get_encoding('all'));
   ?>
</pre>

Output

array(3) {
   ["input_encoding"]=>
   string(5) "UTF-8"
   ["output_encoding"]=>
   string(10) "ISO-8859-1"
   ["internal_encoding"]=>
   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

<?php
   // Using only internal encoding
   iconv_set_encoding("internal_encoding", "UTF-8");
   var_dump(iconv_get_encoding('internal_encoding'));
?>

Output

string(5) "UTF-8"
raja
Published on 21-Aug-2021 07:40:31
Advertisements