seems_utf8( string $str ): bool
- Since
- 1.2.1
- Source
wp-includes/formatting.php:884
Description
NOTE: This function checks for 5-Byte sequences, UTF8 has Bytes Sequences with a maximum length of 4.
Compatibility
Deprecated in WordPress 6.9.0. Use {@see wp_is_valid_utf8()} instead.
- WordPress
- since 1.2.1
- 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
$strstring- The string to be checked.
Return value
bool- True if $str fits a UTF-8 model, false otherwise.
Performance profile
How much work a call to seems_utf8() 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
- Light
- Scaling
- Scales with input
- Instructions
- 16–53
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 67.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below seems_utf8()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost seems_utf8() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$i | 16 | _deprecated_function(), mbstring_binary_safe_encoding(), reset_mbstring_encoding() |
$i | 31–46 | _deprecated_function(), mbstring_binary_safe_encoding(), reset_mbstring_encoding(), ord() |
$i && $j && $length !== false | 38–53 | _deprecated_function(), mbstring_binary_safe_encoding(), reset_mbstring_encoding(), ord(), ord() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 67 instructions, 16–53 executed per call, 10 branches. The work does not change between versions.
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 · 3
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
Source code
function seems_utf8( $str ) { _deprecated_function( __FUNCTION__, '6.9.0', 'wp_is_valid_utf8()' ); mbstring_binary_safe_encoding(); $length = strlen( $str ); reset_mbstring_encoding(); for ( $i = 0; $i < $length; $i++ ) { $c = ord( $str[ $i ] ); if ( $c < 0x80 ) { $n = 0; // 0bbbbbbb } elseif ( ( $c & 0xE0 ) === 0xC0 ) { $n = 1; // 110bbbbb } elseif ( ( $c & 0xF0 ) === 0xE0 ) { $n = 2; // 1110bbbb } elseif ( ( $c & 0xF8 ) === 0xF0 ) { $n = 3; // 11110bbb } elseif ( ( $c & 0xFC ) === 0xF8 ) { $n = 4; // 111110bb } elseif ( ( $c & 0xFE ) === 0xFC ) { $n = 5; // 1111110b } else { return false; // Does not match any model. } for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow? if ( ( ++$i === $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) !== 0x80 ) ) { return false; } } } return true;}Changelog
Introduced in 1.2.1. 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.0.4 tag, from
src/wp-includes/formatting.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.