PHP iconv_get_encoding() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
iconv

Definition

In PHP, iconv_get_encoding() returns the current iconv encoding settings: input, output and internal.

Call it with a type name to get one value, or with no argument to get all three in an array.

Syntax

Call iconv_get_encoding() with the values you need. Start with this line.

PHP
$enc = iconv_get_encoding("internal_encoding");
CallWhat it does
iconv_get_encoding("internal_encoding")Returns the internal encoding, for example "UTF-8".
iconv_get_encoding()Returns all three settings as an array.

Since PHP 5.6 the defaults come from the default_charset setting, which is UTF-8 in most installs.

Library declarations
PHP
iconv_get_encoding(string $type = "all"): string|array|false

Parameters

ParameterDescription
typeOptional. "all" (default), "input_encoding", "output_encoding" or "internal_encoding".

Return Value

Return ValueDescription
stringThe value of one setting.
arrayAn array with the keys input_encoding, output_encoding and internal_encoding when the type is "all".
falseReturned on failure.

PHP Examples

Example 1 — Read the Internal Encoding

Print one setting. The output is typical for a UTF-8 server.

PHP
<?php
echo iconv_get_encoding("internal_encoding"), PHP_EOL;

How It Works

  1. Pass the type name. internal_encoding is the encoding PHP uses inside iconv.
  2. Get a string. It is usually UTF-8.
  3. Print it. echo shows the name.
  4. Expect other values on other servers. They depend on php.ini.

Example 2 — Read All Settings

Call it with no argument to get an array. The output is typical.

PHP
<?php
print_r(iconv_get_encoding());

How It Works

  1. Leave out the argument. The default is all.
  2. Get an array. It has three keys.
  3. Read each key. They tell you how PHP converts input, output and internal text.
  4. Use print_r() to see the whole array.

Example 3 — Loop Through the Settings

Print each setting on its own line. The output is typical.

PHP
<?php
foreach (iconv_get_encoding("all") as $type => $encoding) {
    echo $type, " = ", $encoding, PHP_EOL;
}

How It Works

  1. Pass "all". It is the same as no argument.
  2. Loop with foreach. The key is the type and the value is the encoding.
  3. Print each pair. echo joins the pieces with commas.
  4. Use the loop to log your settings when you debug.

Frequently Asked Questions

iconv_get_encoding() returns the current iconv encoding settings for input, output and internal text.
iconv_get_encoding(string $type = "all"): string|array|false. Pass a type name or nothing at all.
You can pass all, input_encoding, output_encoding or internal_encoding.
Since PHP 5.6 they come from the default_charset setting, which is UTF-8 by default.
iconv_set_encoding() can change them, but it is deprecated. Set default_charset in php.ini instead.

Next: iconv_mime_decode()

iconv_mime_decode() decodes one MIME header field into readable text.

iconv_mime_decode() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful