Frage

In one of my database table I found some corrupted words like:

Noël, japón, Świata

Which I later found should be as:

Noël, japón, świata

Anyone know how to convert them back to normal using PHP

War es hilfreich?

Lösung

Alternatively you can check if the problem is related to the character encoding using iconv - Check the php manual

Andere Tipps

Unfortunately, it's not revertible by using php conversion. I've just made a PHP script which tries all combinations, more than once (up to 5 times) and none of them yields "japón". So it's not possible.

script:

<?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";
        }
    }
}

... grepping the output catches no "japón"

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top