Symfony\Polyfill\Mbstring

Mbstring::prepareSearch │ private static │ CF7 1.0

Метод класса: Mbstring{}

Хуков нет.

Возвращает

array{string, string, bool, int}|null. The haystack and the needle to search, whether offsets in them count bytes rather than UTF-8 characters, and how many bytes of ill-formed sequences iconv() dropped from the haystack

Использование

$result = Mbstring::prepareSearch( $haystack, $needle, $encoding, $fold, $markIllFormed );
$haystack(строка) (обязательный)
.
$needle(строка) (обязательный)
.
$encoding(строка) (обязательный)
.
$fold(true|false) (обязательный)
.
$markIllFormed(true|false) (обязательный)
.

Код Mbstring::prepareSearch() CF7 6.2.4.1

private static function prepareSearch(string $haystack, string $needle, string $encoding, bool $fold, bool $markIllFormed)
{
    if ('ASCII' === $encoding || ('CP850' === $encoding && !$fold)) {
        if ('ASCII' === $encoding) {
            // Native mbstring turns every byte above 0x7F into the same error marker
            $haystack = preg_replace('/[\x80-\xFF]/', "\xFF", $haystack);
            $needle = preg_replace('/[\x80-\xFF]/', "\xFF", $needle);
        }

        if ($fold) {
            $haystack = strtr($haystack, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
            $needle = strtr($needle, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
        }

        return [$haystack, $needle, true, 0];
    }

    $dropped = 0;

    if ('UTF-8' !== $encoding) {
        if (false === ($haystack = self::utf8($haystack, $encoding, $dropped)) || false === $needle = self::utf8($needle, $encoding)) {
            return null;
        }
    } elseif ($markIllFormed) {
        $haystack = self::markIllFormedUtf8($haystack);
        $needle = self::markIllFormedUtf8($needle);
    }

    return $fold ? [self::foldCase($haystack), self::foldCase($needle), false, $dropped] : [$haystack, $needle, false, $dropped];
}