PHP – Set the current setting for character encoding conversion using iconv_set_encoding() function

PHPServer Side ProgrammingProgramming

In PHP, the iconv_set_encoding() function is used to set the current character encoding conversion. It is an inbuilt function in PHP that changes the value of the internal configuration variable specified by type to encoding.

Syntax

string iconv_set_encoding(string $type, string $encoding)

Parameters

iconv_set_encoding() takes two parameters − $type and $encoding.

  • $type − The $type parameter can be input_encoding, output_encoding or internal_encoding.

  • $encoding − The $encoding parameter is used for the character set.

Return Values

iconv_set_encoding() returns True on success and False on failure.

Example

 Live Demo

<pre>
   <?php
      // internal_encoding is string $type
      //UTF-8 is string $charset
      $bool = iconv_set_encoding ("internal_encoding","UTF-8");

      // it will shows the new encoding
      $mixed = iconv_get_encoding();
      var_dump($mixed);
   ?>
</pre>

Output

array(3) {
   ["input_encoding"]=>
   string(5) "UTF-8"
   ["output_encoding"]=>
   string(5) "UTF-8"
   ["internal_encoding"]=>
   string(5) "UTF-8"
}
raja
Updated on 21-Aug-2021 07:51:05

Advertisements