I
I
IgorRastarov2017-05-10 10:49:25
PHP
IgorRastarov, 2017-05-10 10:49:25

Why is iconv not working properly?

Hello. Here is a piece of modx plugin code.

foreach ($rows as $row) {
    $row[0] = iconv('CP1251','UTF-8',$row[0]);
    $btn = "<a class='button show-form' data-flat='{$row[0]}:{$row[2]}:".number_format((int)$row[6], 0, ',', ' ')." руб.:".(!empty($row[7])?number_format($row[7], 0, ',', ' ').' руб.':"-").">Текст</a>";
    $out .= "<tr>";
    $out .= "<td>{$row[0]}</td>";
    $out .= "<td>{$row[1]}</td>";
    $out .= "<td>{$row[2]}</td>";
    $out .= "<td>{$row[3]}</td>";
    $out .= "<td>{$row[4]}</td>";
    $out .= "<td>{$row[5]}</td>";
    $out .= "<td class='nowrap'><span class='".(!empty($row[7])?'strikethrough': '')."'>".number_format((int)$row[6], 0, ',', ' ')." руб.</span></td>";
    $out .= "<td class='nowrap action-price'>".(!empty($row[7])?number_format($row[7], 0, ',', ' ').' руб.': "")."</td>";
    $out .= "<td>".(!empty($row[8])?iconv('CP1251','UTF-8',$row[8]): $btn)."</td>";
    $out .= "</tr>";
    //echo "<pre>";print_r(iconv('CP1251','UTF-8',$row[8])); echo "</pre>";

}

Iconv fails for $row[8]. Works only if in the csv file before the desired Text put a number.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-05-10
@IgorRastarov

This means that you are sending text in one encoding, but specifying another ('CP1251').
To check, put somewhere the php-FILE test-case with ONE line
<?= iconv(...) ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question