PHP mb_list_encodings() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
mbstring

Definition

In PHP, mb_list_encodings() returns an array with the names of every character encoding the mbstring extension supports.

Use it to check whether an encoding is available before you rely on it.

Syntax

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

PHP
$encodings = mb_list_encodings();
CallWhat it does
mb_list_encodings()Returns an array of encoding names.
in_array("UTF-8", mb_list_encodings())Checks that UTF-8 is available.

The list differs a little between PHP versions, so print it on your own server to be sure.

Library declarations
PHP
mb_list_encodings(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayA list of encoding names, such as UTF-8 and ISO-8859-1.

PHP Examples

Example 1 — Check That UTF-8 Is Supported

Search the list for one encoding name.

PHP
<?php
$encodings = mb_list_encodings();

var_dump(in_array("UTF-8", $encodings));

How It Works

  1. Get the list of encodings.
  2. Search it with in_array().
  3. UTF-8 is always in the list.
  4. You get true.

Example 2 — Check Several Encodings

Loop over names and print which ones are supported.

PHP
<?php
$list = mb_list_encodings();

foreach (["UTF-8", "ISO-8859-1", "SJIS", "KLINGON"] as $name) {
    echo $name, ": ", in_array($name, $list, true) ? "yes" : "no", PHP_EOL;
}

How It Works

  1. Get the list once.
  2. Loop over the names you care about.
  3. Test each with in_array() in strict mode.
  4. An invented name gives no.

Example 3 — Peek at the List

Print the first five names. The output is a typical sample, because the list changes between PHP versions.

PHP
<?php
$first = array_slice(mb_list_encodings(), 0, 5);

print_r($first);

How It Works

  1. Take the first five items with array_slice().
  2. Print them with print_r().
  3. The names are real encoding names.
  4. Expect a different list on your server.

Frequently Asked Questions

mb_list_encodings() returns an array of all character encodings the mbstring extension supports.
mb_list_encodings(): array. It takes no arguments.
Almost. It can differ a little between PHP versions and builds.
Use mb_encoding_aliases() with an encoding name to see its aliases.
With in_array() in strict mode, yes. Write names as they appear in the list, such as UTF-8.

Next: mb_strlen()

mb_strlen() counts the characters in a string, not the bytes.

mb_strlen() 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