getid3_lib::iconv_fallback( string $in_charset, string $out_charset, string $string ): string
- Source
wp-includes/ID3/getid3.lib.php:1240
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$in_charsetstring$out_charsetstring$stringstring
Return value
string
Performance profile
How much work a call to getid3_lib::iconv_fallback() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–51
- Plugin surface
- None
- Called by
- 5
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 55.
Nothing here hands control to plugin code.
5 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost getid3_lib::iconv_fallback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$in_charset == false | 6 | none |
$in_charset != false | 23–35 | strtoupper(), strtoupper(), strtoupper() |
$in_charset != false | 25–37 | strtoupper(), strtoupper(), mb_convert_encoding() |
$in_charset != false | 30–46 | strtoupper(), strtoupper(), strtoupper(), mb_convert_encoding() |
$in_charset != false && $out_charset == "ISO-8859-1" | 32–42 | strtoupper(), strtoupper(), mb_convert_encoding(), rtrim() |
$in_charset != false && $out_charset == "ISO-8859-1" | 37–51 | strtoupper(), strtoupper(), strtoupper(), mb_convert_encoding(), rtrim() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 79 | 6–55 | 13 | 24 more instructions than PHP 8.5 |
| 8.5 | 55 | 6–51 | 10 | |
| 8.4 | 55 | 6–51 | 10 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 61 | 6–57 | 10 | |
| 8.2 | 61 | 6–57 | 10 | |
| 8.1 | 61 | 6–57 | 10 | 1 more instruction than PHP 7.4 |
| 7.4 | 60 | 6–57 | 10 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 2
- getid3_lib::[object Object]()
- Exception::__construct()Create a new exception
Used by · 5
- getID3::CharConvert()Converts array to $encoding charset from $this->encoding.
- getid3_asf::TrimConvert()Remove terminator 00 00 and convert UTF-16LE to Latin-1.
- getid3_asf::WMpictureTypeLookup()
- getid3_id3v2::ParseID3v2Frame()
- getid3_lib::CopyTagsToComments()
Source code
public static function iconv_fallback($in_charset, $out_charset, $string) { if ($in_charset == $out_charset) { return $string; } // mb_convert_encoding() available if (function_exists('mb_convert_encoding')) { if ((strtoupper($in_charset) == 'UTF-16') && (substr($string, 0, 2) != "\xFE\xFF") && (substr($string, 0, 2) != "\xFF\xFE")) { // if BOM missing, mb_convert_encoding will mishandle the conversion, assume UTF-16BE and prepend appropriate BOM $string = "\xFF\xFE".$string; } if ((strtoupper($in_charset) == 'UTF-16') && (strtoupper($out_charset) == 'UTF-8')) { if (($string == "\xFF\xFE") || ($string == "\xFE\xFF")) { // if string consists of only BOM, mb_convert_encoding will return the BOM unmodified return ''; } } if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) { switch ($out_charset) { case 'ISO-8859-1': $converted_string = rtrim($converted_string, "\x00"); break; } return $converted_string; } return $string; // iconv() available } elseif (function_exists('iconv')) { if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) { switch ($out_charset) { case 'ISO-8859-1': $converted_string = rtrim($converted_string, "\x00"); break; } return $converted_string; } // iconv() may sometimes fail with "illegal character in input string" error message // and return an empty string, but returning the unconverted string is more useful return $string; } // neither mb_convert_encoding or iconv() is available static $ConversionFunctionList = array(); if (empty($ConversionFunctionList)) { $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8'; $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16'; $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be'; $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le'; $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591'; $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16'; $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be'; $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le'; $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591'; $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8'; $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591'; $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8'; $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591'; $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8'; } if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) { $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]; return self::$ConversionFunction($string); } throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset); }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/ID3/getid3.lib.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.