Skip to content

Instantly share code, notes, and snippets.

@paramah
Created October 20, 2011 09:51
Show Gist options
  • Save paramah/1300786 to your computer and use it in GitHub Desktop.
Save paramah/1300786 to your computer and use it in GitHub Desktop.
brokenUTF
function brokenUTF($tbl, $id) {
header('Content-Type: text/html; charset=utf-8');
echo "<pre>";
echo "Konwersja: ".$tbl."</br/>";
$sql = new MySQLi("HOST", "USER", "HASLO", "BAZA");
$cnt = $sql->query('SELECT COUNT(' . $id . ') AS count FROM ' . $tbl);
$cnt = $cnt->fetch_assoc();
$cnt = $cnt['count'];
$all = $sql->query('SELECT * FROM ' . $tbl);
$columns = $sql->query('SHOW COLUMNS FROM ' . $tbl);
while($clmn = $columns->fetch_assoc()) { $clmns[] = $clmn['Field']; }
$sql->query('SET NAMES utf8');
while($row = $all->fetch_assoc())
{
$i = 0;
$set = '';
foreach($clmns as $clmn)
{
if($clmn != $id)
{
if($i != 0)
{
$set .= ', ';
}
$msg = $row[$clmn];
$msg=str_replace("Ä…","ą",$msg);
$msg=str_replace("ć","ć",$msg);
$msg=str_replace("Ä™","ę",$msg);
$msg=str_replace("ó","ó",$msg);
$msg=str_replace("Å‚","ł",$msg);
$msg=str_replace("Å„","ń",$msg);
$msg=str_replace("Å›","ś",$msg);
$msg=str_replace("ż","ż",$msg);
$msg=str_replace("Ĺş","ź",$msg);
$msg=str_replace("Ă“","Ó",$msg);
$set .= $clmn . '="' . addslashes($msg) . '"';
$i++;
}
}
$sql->query('UPDATE ' . $tbl . ' SET ' . $set . ' WHERE ' . $id . '=' . $row[$id]);
}
unset($sql);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment