W3cubDocs

/Drupal 8

function drupal_validate_utf8

drupal_validate_utf8($text)

Checks whether a string is valid UTF-8.

All functions designed to filter input should use drupal_validate_utf8 to ensure they operate on valid UTF-8 strings to prevent bypass of the filter.

When text containing an invalid UTF-8 lead byte (0xC0 - 0xFF) is presented as UTF-8 to Internet Explorer 6, the program may misinterpret subsequent bytes. When these subsequent bytes are HTML control characters such as quotes or angle brackets, parts of the text that were deemed safe by filters end up in locations that are potentially unsafe; An onerror attribute that is outside of a tag, and thus deemed safe by a filter, can be interpreted by the browser as if it were inside the tag.

The function does not return FALSE for strings containing character codes above U+10FFFF, even though these are prohibited by RFC 3629.

Parameters

$text: The text to check.

Return value

bool TRUE if the text is valid UTF-8, FALSE if not.

Deprecated

in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use \Drupal\Component\Utility\Unicode::validateUtf8().

See also

\Drupal\Component\Utility\Unicode::validateUtf8()

File

core/includes/bootstrap.inc, line 346
Functions that need to be loaded on every Drupal request.

Code

function drupal_validate_utf8($text) {
  return Unicode::validateUtf8($text);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!bootstrap.inc/function/drupal_validate_utf8/8.1.x