public static function Unicode::substr in Drupal 8
Cuts off a piece of a string based on character indices and counts.
Follows the same behavior as PHP's own substr() function. Note that for cutting off a string at a known character/substring location, the usage of PHP's normal strpos/substr is safe and much faster.
Parameters
string $text: The input string.
int $start: The position at which to start reading.
int $length: The number of characters to read.
Return value
string The shortened string.
Deprecated
in drupal:8.6.0 and is removed from drupal:9.0.0. Use mb_substr() instead.
See also
https://www.drupal.org/node/2850048
1 call to Unicode::substr()
- UnicodeTest::testSubstr in core/
tests/ Drupal/ Tests/ Component/ Utility/ UnicodeTest.php - Tests multibyte substr.
File
- core/
lib/ Drupal/ Component/ Utility/ Unicode.php, line 381
Class
- Unicode
- Provides Unicode-related conversions and operations.
Namespace
Drupal\Component\UtilityCode
public static function substr($text, $start, $length = NULL) {
@trigger_error('\\Drupal\\Component\\Utility\\Unicode::substr() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use mb_substr() instead. See https://www.drupal.org/node/2850048.', E_USER_DEPRECATED);
return mb_substr($text, $start, $length);
}