function Iconv::iconv_substr
1 call to Iconv::iconv_substr()
- Iconv::iconv_strpos in vendor/
symfony/ polyfill-iconv/ Iconv.php
File
-
vendor/
symfony/ polyfill-iconv/ Iconv.php, line 524
Class
- Iconv
- iconv implementation in pure PHP, UTF-8 centric.
Namespace
Symfony\Polyfill\IconvCode
public static function iconv_substr($s, $start, $length = 2147483647, $encoding = null) {
if (null === $encoding) {
$encoding = self::$internalEncoding;
}
if (0 !== stripos($encoding, 'utf-8')) {
$encoding = null;
}
elseif (false === ($s = self::iconv($encoding, 'utf-8', $s))) {
return false;
}
$s = (string) $s;
$slen = self::iconv_strlen($s, 'utf-8');
$start = (int) $start;
if (0 > $start) {
$start += $slen;
}
if (0 > $start) {
if (\PHP_VERSION_ID < 80000) {
return false;
}
$start = 0;
}
if ($start >= $slen) {
return \PHP_VERSION_ID >= 80000 ? '' : false;
}
$rx = $slen - $start;
if (0 > $length) {
$length += $rx;
}
if (0 === $length) {
return '';
}
if (0 > $length) {
return \PHP_VERSION_ID >= 80000 ? '' : false;
}
if ($length > $rx) {
$length = $rx;
}
$rx = '/^' . ($start ? self::pregOffset($start) : '') . '(' . self::pregOffset($length) . ')/u';
$s = preg_match($rx, $s, $s) ? $s[1] : '';
if (null === $encoding) {
return $s;
}
return self::iconv('utf-8', $encoding, $s);
}