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

Breadcrumb

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

function Utils::stringToUTF8Array

Converts a string to an array of UTF-8 characters

Parameters

string $str String to convert:

bool $strictEncoding If false and the string contains invalid: UTF-8 characters, it will replace those characters with the one defined in the mbstring.substitute_character setting

Return value

array

Throws

EncodingException

3 calls to Utils::stringToUTF8Array()
LSM::add in vendor/mck89/peast/lib/Peast/Syntax/LSM.php
Adds a sequence
LSM::remove in vendor/mck89/peast/lib/Peast/Syntax/LSM.php
Removes a sequence
Scanner::__construct in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Class constructor

File

vendor/mck89/peast/lib/Peast/Syntax/Utils.php, line 32

Class

Utils
Utilities class.

Namespace

Peast\Syntax

Code

public static function stringToUTF8Array($str, $strictEncoding = true) {
    if ($str === "") {
        return array();
    }
    $ret = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
    if (preg_last_error() === PREG_BAD_UTF8_ERROR) {
        if (!$strictEncoding) {
            $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
            $ret = self::stringToUTF8Array($str, false);
        }
        else {
            throw new EncodingException("String contains invalid UTF-8");
        }
    }
    return $ret;
}

API Navigation

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