西里尔符号的问题

The following code doesn't detect encoding correct.

$data = 'ABCDEG АБВГДЕ';
$charset = mb_detect_encoding($data);
$data = iconv($charset, "UTF-8", $data);
$data = mb_strtolower($data, 'UTF-8');
$datasort = str_replace(array("", "
", " "), '', $data);
$counter = mb_strlen($datasort,'UTF-8');
foreach (count_chars($datasort, 1) as $i => $val) 
{
echo '
<tr>
    <th scope="row">'.mb_detect_encoding(chr($i)).'</th>
// ON LATIN SYMBOLS IT DETECTED ANCII AND ON CYRILLIC IT DETECTED **NOTHING**
</tr>
';
}

Where here could be the problem? //php file have UTF-8 encoding

Try this and all that will be ASCII Or UTF-8 : the problem with your code is that count_chars change the encoding during the convert...

function mbStringToArray ($string) {
    $strlen = mb_strlen($string);
    while ($strlen) {
        $array[] = mb_substr($string,0,1,"UTF-8");
        $string = mb_substr($string,1,$strlen,"UTF-8");
        $strlen = mb_strlen($string);
    }
    return $array;
} 

$data = 'ABCDEG АБВГДЕ';
$data = str_replace(array("", "
", " "), '', mb_strtolower($data));
iconv(mb_detect_encoding($data, mb_detect_order(), true), "UTF-8", $data);

$data = mbStringToArray($data);

echo '<table>';
foreach ($data as $i => $val) 
{
echo '
<tr>
    <th scope="row">'. $val . ' : ' .mb_detect_encoding(chr($i)).'</th>
</tr>
';
}
echo '</table>';

A : ASCII B : UTF-8 C : UTF-8 D : UTF-8 E : UTF-8 G : UTF-8 А : UTF-8 Б : UTF-8 В : UTF-8 Г : ASCII Д : ASCII Е : UTF-8