SimilarText\Finder::utf8ToExtendedAscii PHP Method

utf8ToExtendedAscii() protected method

Ensure a string only uses ascii characters.
protected utf8ToExtendedAscii ( string $str, array &$map ) : string
$str string
$map array
return string
    protected function utf8ToExtendedAscii($str, &$map)
    {
        // Find all multi-byte characters (cf. utf-8 encoding specs).
        $matches = array();
        if (!preg_match_all('/[\\xC0-\\xF7][\\x80-\\xBF]+/', $str, $matches)) {
            return $str;
            // plain ascii string
        }
        // Update the encoding map with the characters not already met.
        foreach ($matches[0] as $mbc) {
            if (!isset($map[$mbc])) {
                $map[$mbc] = chr(128 + count($map));
            }
        }
        // Finally remap non-ascii characters.
        return strtr($str, $map);
    }