function public static function Unicode::isSimple

8.x-3.x Unicode.php public static Unicode::isSimple($string, $length = 250, $allowed_tags = NULL, &$html = FALSE)

Determines if a string of text is considered "simple".


string $string: The string of text to check "simple" criteria on.

int|false $length: The length of characters used to determine whether or not $string is considered "simple". Set explicitly to FALSE to disable this criteria.

array|false $allowed_tags: An array of allowed tag elements. Set explicitly to FALSE to disable this criteria.

bool $html: A variable, passed by reference, that indicates whether or not the string contains HTML.

Return value

bool Returns TRUE if the $string is considered "simple", FALSE otherwise.


Extends \Drupal\Component\Utility\Unicode.



Source src/Utility/Unicode.php (line 131)

public static function isSimple($string, $length = 250, $allowed_tags = NULL, &$html = FALSE) {
  // Typecast to a string (if an object).
  $string_clone = (string) $string;

  // Use the advanced drupal_static() pattern.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['strings'] = &drupal_static(__METHOD__);
  $strings = &$drupal_static_fast['strings'];
  if (!isset($strings[$string_clone])) {
    $plain_string = strip_tags($string_clone);
    $simple = TRUE;
    if ($allowed_tags !== FALSE) {
      $filtered_string = Xss::filter($string_clone, $allowed_tags);
      $html = $filtered_string !== $plain_string;
      $simple = $simple && $string_clone === $filtered_string;
    if ($length !== FALSE) {
      $simple = $simple && strlen($plain_string) <= intval($length);
    $strings[$string_clone] = $simple;
  return $strings[$string_clone];