acf_strlen()
Gets the length of the supplied string. It is most often used to calculate the length of a string sent through $_POST.
The function works as follows:
- Removes slashes from the supplied string with wp_unslash().
- Decodes HTML entities to their HTML characters with wp_specialchars_decode(), because wp_kses() normalizes entities.
- Replaces
\r\nwith\n. - Uses mb_strlen() to calculate the string length.
No Hooks.
Returns
Int.
Usage
acf_strlen( $str );
- $str(string) (required)
- String to analyze.
Examples
#1 Examples of return values
acf_strlen( 'hello world' ); // > 11 characters acf_strlen( 'he\llo wor\ld' ); // > 11 characters
Changelog
| Since 5.9.0 | Introduced. |
acf_strlen() acf strlen code ACF 6.8.8
function acf_strlen( $str ) {
return mb_strlen( str_replace( "\r\n", "\n", wp_specialchars_decode( wp_unslash( $str ) ) ) );
}