Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UTF8Utils.php

function UTF8Utils::countChars

Count the number of characters in a string. UTF-8 aware. This will try (in order) iconv, MB, and finally a custom counter.

Parameters

string $string:

Return value

int

2 calls to UTF8Utils::countChars()
Scanner::columnOffset in vendor/masterminds/html5/src/HTML5/Parser/Scanner.php
Returns the current column of the current line that the tokenizer is at.
StringInputStream::columnOffset in vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php
Returns the current column of the current line that the tokenizer is at. Newlines are column 0. The first char after a newline is column 1.

File

vendor/masterminds/html5/src/HTML5/Parser/UTF8Utils.php, line 47

Class

UTF8Utils

Namespace

Masterminds\HTML5\Parser

Code

public static function countChars($string) {
    // Get the length for the string we need.
    if (function_exists('mb_strlen')) {
        return mb_strlen($string, 'utf-8');
    }
    if (function_exists('iconv_strlen')) {
        return iconv_strlen($string, 'utf-8');
    }
    $count = count_chars($string);
    // 0x80 = 0x7F - 0 + 1 (one added to get inclusive range)
    // 0x33 = 0xF4 - 0x2C + 1 (one added to get inclusive range)
    return array_sum(array_slice($count, 0, 0x80)) + array_sum(array_slice($count, 0xc2, 0x33));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal