wpseek.com
WordPress开发者和主题制作者的搜索引擎
_wp_scrub_utf8_fallback is private and should not be used in themes or plugins directly.
_wp_scrub_utf8_fallback › WordPress Function
Since6.9.0
已弃用n/a
› _wp_scrub_utf8_fallback ( $bytes )
| 访问: |
|
| 参数: |
|
| 查看: |
|
| 返回: |
|
| 定义在: |
|
| 文档: |
Fallback mechanism for replacing invalid spans of UTF-8 bytes.
Example: 'Pi�a' === _wp_scrub_utf8_fallback( "PixF1a" ); // “ñ” is 0xF1 in Windows-1252.Related Functions: _wp_is_valid_utf8_fallback, _wp_utf8_decode_fallback, _wp_utf8_encode_fallback, wp_rel_callback, _wp_scan_utf8
源码
function _wp_scrub_utf8_fallback( string $bytes ): string {
$bytes_length = strlen( $bytes );
$next_byte_at = 0;
$was_at = 0;
$invalid_length = 0;
$scrubbed = '';
while ( $next_byte_at <= $bytes_length ) {
_wp_scan_utf8( $bytes, $next_byte_at, $invalid_length );
if ( $next_byte_at >= $bytes_length ) {
if ( 0 === $was_at ) {
return $bytes;
}
return $scrubbed . substr( $bytes, $was_at, $next_byte_at - $was_at - $invalid_length );
}
$scrubbed .= substr( $bytes, $was_at, $next_byte_at - $was_at );
$scrubbed .= "\u{FFFD}";
$next_byte_at += $invalid_length;
$was_at = $next_byte_at;
}
return $scrubbed;
}