1 unicode.inc backdrop_strlen($text)

Counts the number of characters in a UTF-8 string.

This is less than or equal to the byte count.


string $text: The string to run the operation on.

Return value

integer: The length of the string.

Related topics


core/includes/unicode.inc, line 480
Provides Unicode-related conversions and operations.


function backdrop_strlen($text) {
  // Bail early if $text is NULL.
  // @todo Remove this in 2.x.
  if (is_null($text)) {
    return 0;

  global $multibyte;
  if ($multibyte == UNICODE_MULTIBYTE) {
    return mb_strlen($text);
  else {
    // Do not count UTF-8 continuation bytes.
    return strlen(preg_replace("/[\x80-\xBF]/", '', $text));