_wp_scan_utf8


_wp_scan_utf8 ( $bytes, $at, $invalid_length, $max_bytes = null, $max_code_points = null, $has_noncharacters = null )

Access:
  • private
Parameters:
  • (string) bytes UTF-8 encoded string which might include invalid spans of bytes.
  • (int) at Where to start scanning.
  • (int) invalid_length Will be set to how many bytes are to be ignored after `$at`.
  • (int|null) max_bytes Stop scanning after this many bytes have been seen.
  • (int|null) max_code_points Stop scanning after this many code points have been seen.
  • (bool|null) has_noncharacters Set to indicate if scanned string contained noncharacters.
Returns:
  • (int) How many code points were successfully scanned.
Defined at:

Description

Finds spans of valid and invalid UTF-8 bytes in a given string.This is a low-level tool to power various UTF-8 functionality. It scans through a string until it finds invalid byte spans. When it does this, it does three things: - Assigns `$at` to the position after the last successful code point. - Assigns `$invalid_length` to the length of the maximal subpart of the invalid bytes starting at `$at`. - Returns how many code points were successfully scanned. This information is enough to build a number of useful UTF-8 functions. Example: // ñ is U+F1, which in `ISO-8859-1`/`latin1`/`Windows-1252`/`cp1252` is 0xF1. "Pi\xF1a" === $pineapple = mb_convert_encoding( "Piña", 'Windows-1252', 'UTF-8' ); $at = $invalid_length = 0; // The first step finds the invalid 0xF1 byte. 2 === _wp_scan_utf8( $pineapple, $at, $invalid_length ); $at === 2; $invalid_length === 1; // The second step continues to the end of the string. 1 === _wp_scan_utf8( $pineapple, $at, $invalid_length ); $at === 4; $invalid_length === 0; Note! While passing an options array here might be convenient from a calling-code standpoint, this function is intended to serve as a very low-level foundation upon which to build higher level functionality. For the sake of keeping costs explicit all arguments are passed directly.

Related Functions

_wp_scrub_utf8_fallback, wp_sprintf, wp_salt, wp_check_invalid_utf8, _wp_cron

Top Google Results

User discussions

wpseek mobile