wpseek.com
A WordPress-centric search engine for devs and theme authors
_wp_utf8_encode_fallback is private and should not be used in themes or plugins directly.
_wp_utf8_encode_fallback › WordPress Function
Since6.9.0
Deprecatedn/a
› _wp_utf8_encode_fallback ( $iso_8859_1_text )
| Access: |
|
| Parameters: |
|
| See: |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Converts a string from ISO-8859-1 to UTF-8, maintaining backwards compatibility with the deprecated function from the PHP standard library.
Source
function _wp_utf8_encode_fallback( $iso_8859_1_text ) {
$iso_8859_1_text = (string) $iso_8859_1_text;
$at = 0;
$was_at = 0;
$end = strlen( $iso_8859_1_text );
$utf8 = '';
while ( $at < $end ) {
// US-ASCII bytes are identical in ISO-8859-1 and UTF-8. These are 0x00–0x7F.
$ascii_byte_count = strspn(
$iso_8859_1_text,
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" .
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" .
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f",
$at
);
if ( $ascii_byte_count > 0 ) {
$at += $ascii_byte_count;
continue;
}
// All other bytes transform into two-byte UTF-8 sequences.
$code_point = ord( $iso_8859_1_text[ $at ] );
$byte1 = chr( 0xC0 | ( $code_point >> 6 ) );
$byte2 = chr( 0x80 | ( $code_point & 0x3F ) );
$utf8 .= substr( $iso_8859_1_text, $was_at, $at - $was_at );
$utf8 .= "{$byte1}{$byte2}";
++$at;
$was_at = $at;
}
if ( 0 === $was_at ) {
return $iso_8859_1_text;
}
$utf8 .= substr( $iso_8859_1_text, $was_at );
return $utf8;
}