如何使用 PHP 修复损坏的编码单词



在我的一个数据库表中,我发现了一些损坏的单词,例如:

Noël, japón, Świata

我后来发现应该是:

Noël, japón, świata

任何人都知道如何使用PHP将它们转换回正常状态

或者,您可以使用iconv检查问题是否与字符编码有关 - 查看 php 手册

不幸的是,它不能通过使用 php 转换来恢复。我刚刚制作了一个PHP脚本,它尝试了所有组合,不止一次(最多5次),但没有一个产生"japón"。所以这是不可能的。

脚本:

<?php
$encodings=mb_list_encodings();
foreach($encodings as $enc_to) {
    foreach($encodings as $enc_from) {
        $str="Noël, japón, Świata";
        for ($i=0;$i<5;$i++) {
            $str=mb_convert_encoding($str,$enc_to,$enc_from);
            echo "$enc_from -> $enc_to ($i): ".$str."n";
            echo "$enc_from -> $enc_to ($i) + html_entity_decode: ".html_entity_decode($str)."n";
            echo "$enc_from -> $enc_to ($i) + htmlspecialchars_decode: ".htmlspecialchars_decode($str)."n";
            echo "$enc_from -> $enc_to ($i) + urldecode: ".urldecode($str)."n";
            echo "$enc_from -> $enc_to ($i) + htmlentities: ".htmlentities($str)."n";
            echo "$enc_from -> $enc_to ($i) + htmlspecialchars: ".htmlspecialchars($str)."n";
            echo "$enc_from -> $enc_to ($i) + urlencode: ".urlencode($str)."n";
        }
    }
}

。greping 输出不会捕获"japón"

最新更新