mb_preferred_mime_name()

mb_preferred_mime_name() — Get MIME charset string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Get a MIME charset string for a specific encoding.

Signature

mb_preferred_mime_name(string $encoding): string|false

Parameters

ParameterTypeWhat it takes
$encodingstringThe encoding being checked.

Return value

The MIME charset string for character encoding encoding, or false if no charset is preferred for the given encoding.

Example

A runnable snippet:

$outputenc = "sjis-win"; mb_http_output($outputenc); ob_start("mb_output_handler"); header("Content-Type: text/html; charset=" . mb_preferred_mime_name($outputenc));

Changelog

VersionChange
8.0.0Now throws a ValueError if encoding is an invalid encoding. Previously, an E_WARNING was emitted and false was returned.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page mb_preferred_mime_name() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.