function drupal_strlen

7 unicode.inc drupal_strlen($text)
4.7 unicode.inc drupal_strlen($text)
5 unicode.inc drupal_strlen($text)
6 unicode.inc drupal_strlen($text)
8 unicode.inc drupal_strlen($text)

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

This is less than or equal to the byte count.

Parameters

$text: The string to run the operation on.

Return value

integer The length of the string.

Related topics

18 calls to drupal_strlen()
DrupalHtmlToTextTestCase::testVeryLongLineWrap in modules/simpletest/tests/mail.test
Tests that drupal_html_to_text() wraps before 1000 characters.
drupal_html_to_text in includes/mail.inc
Transforms an HTML string into plain text, preserving its structure.
field_create_field in modules/field/field.crud.inc
Creates a field.
hook_field_validate in modules/field/field.api.php
Validate this module's field data.
list_allowed_values_setting_validate in modules/field/modules/list/list.module
Element validate callback; check that the entered values are valid.

... See full list

File

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

Code

function drupal_strlen($text) {
  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));
  }
}