acf_strlen()ACF 5.9.0

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:

  1. Removes slashes from the supplied string with wp_unslash().
  2. Decodes HTML entities to their HTML characters with wp_specialchars_decode(), because wp_kses() normalizes entities.
  3. Replaces \r\n with \n.
  4. 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() code ACF 6.8.8

function acf_strlen( $str ) {
	return mb_strlen( str_replace( "\r\n", "\n", wp_specialchars_decode( wp_unslash( $str ) ) ) );
}