Created
September 1, 2013 18:32
-
-
Save halilim/6406327 to your computer and use it in GitHub Desktop.
Bozuk Türkçe karakter düzelt - Fix corrupt Turkish characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function array_make_first(&$array, $element) { | |
if (($ndx = array_search($element, $array)) !== false) { | |
unset($array[$ndx]); | |
array_unshift($array, $element); | |
} | |
} | |
$encler = mb_list_encodings(); | |
natcasesort($encler); | |
array_make_first($encler, 'ISO-8859-9'); | |
array_make_first($encler, 'UTF-8'); | |
$varsayilanEncIn = 'iso-8859-9'; | |
$varsayilanEncOut = 'utf-8'; | |
if (isset($_FILES['dosya']) && $_FILES['dosya']['error'] == UPLOAD_ERR_OK && isset($_GET['y'])) { | |
$icerik = file_get_contents($_FILES['dosya']['tmp_name']); | |
if (isset($_POST['enc_in']) && $_POST['enc_in'] != '' && $_POST['enc_in'] != '__auto' && in_array($_POST['enc_in'], $encler)) { | |
$enc = $_POST['enc_in']; | |
} else { | |
$autoenc = $enc = mb_detect_encoding($icerik, 'utf-8, iso-8859-9', true); | |
} | |
if (strtolower($enc) != 'utf-8') { | |
echo $enc; | |
$icerik = mb_convert_encoding($icerik, 'utf-8', $enc); | |
} | |
$icerik = strtr($icerik, array( | |
'•' => '•', | |
'“' => '“', | |
'â€' => '”', | |
'‘' => '‘', | |
'’' => '’', | |
'ݾ' => 'İ', | |
'Ý' => 'İ', | |
'Ä°' => 'İ', | |
'Ã' => 'İ', | |
'‹' => 'İ', | |
'Ý' => 'İ', | |
'ý' => 'ı', | |
'ı' => 'ı', | |
'±' => 'ı', | |
'ý' => 'ı', | |
'Û' => 'ı', | |
'›' => 'ı', | |
'ý' => 'ı', | |
'Þ' => 'Ş', | |
'Åž' => 'Ş', | |
'ÅŸ' => 'Ş', | |
'åÿ' => 'Ş', | |
'Þ' => 'Ş', | |
'þ' => 'ş', | |
'Å?' => 'ş', | |
'ÅŸ' => 'ş', | |
'þ' => 'ş', | |
'Ð' => 'Ğ', | |
'Äž' => 'Ğ', | |
'ð' => 'ğ', | |
'Ä?' => 'ğ', | |
'ÄŸ' => 'ğ', | |
'ð' => 'ğ', | |
'Ç' => 'Ç', | |
'Ã?' => 'Ç', | |
'Ç' => 'Ç', | |
'ç' => 'ç', | |
'ç' => 'ç', | |
'Ö' => 'Ö', | |
'Ö' => 'Ö', | |
'ö' => 'ö', | |
'ö' => 'ö', | |
'Ãœ' => 'Ü', | |
'Ü' => 'Ü', | |
'ü' => 'ü', | |
'ã¼' => 'ü', | |
'ü' => 'ü', | |
'ü' => 'ü', | |
)); | |
if (isset($_POST['enc_out']) && $_POST['enc_out'] != '' && in_array($_POST['enc_out'], $encler)) { | |
$icerik = mb_convert_encoding($icerik, $_POST['enc_out'], 'utf-8'); | |
} | |
if ($_POST['tip'] == '2') { | |
$lastDot = strrpos($_FILES['dosya']['name'], '.'); | |
if ($lastDot === false) { | |
$ad = $_FILES['dosya']['name'].'_duzeltilmis'; | |
} else { | |
$ad = substr($_FILES['dosya']['name'], 0, $lastDot).'_duzeltilmis'.substr($_FILES['dosya']['name'], $lastDot); | |
} | |
header("Content-Disposition: attachment; filename=\"".basename($ad)."\";" ); | |
echo $icerik; | |
exit; | |
} | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<style type="text/css"> | |
h1 a, h1 a:visited{color:#09F;text-decoration:none;} | |
h1 a:hover{text-decoration:underline;} | |
</style> | |
<title>Bozuk Türkçe Karakterli Dosya Düzelt</title> | |
</head> | |
<body> | |
<h1><a href=".">Bozuk Türkçe Karakterli Dosya Düzelt (.sql, .html, ...)</a></h1> | |
<form action="?y=1" method="post" enctype="multipart/form-data"> | |
<input type="file" name="dosya" /> | |
<select name="tip"> | |
<option value="1">Ekranda Göster</option> | |
<option value="2">Farklı Kaydet</option> | |
</select> | |
| |
<label for="enc_in">Kodlama</label> <select id="enc_in" name="enc_in"> | |
<option value="__auto">Otomatik tespit et</option> | |
<?php foreach ($encler as $v) { ?> | |
<option value="<?php echo htmlspecialchars($v)?>"<?php echo ((@$_POST['enc_in']==$v/*||$varsayilanEncIn==strtolower($v)*/)?' selected="selected"':''); ?>><?php echo htmlspecialchars($v)?></option> | |
<?php } ?> | |
</select> | |
| |
<label for="enc_out">Çıktı Kodlaması</label> <select id="enc_out" name="enc_out"> | |
<?php foreach ($encler as $v) { ?> | |
<option value="<?php echo htmlspecialchars($v)?>"<?php echo ((@$_POST['enc_out']==$v||$varsayilanEncOut==strtolower($v))?' selected="selected"':''); ?>><?php echo htmlspecialchars($v)?></option> | |
<?php } ?> | |
</select> | |
| |
<input type="submit" value="Yükle"> | |
</form> | |
<?if ($icerik){ ?> | |
<br /> | |
<?php if (isset($autoenc)) echo 'Tespit edilen girdi kodlaması: '.$autoenc.'<br />' ?> | |
Sonuç :<br /> | |
<textarea cols="" rows="" readonly="readonly" wrap="off" style="width: 100%; height: 600px; font-family:monospace;white-space: pre;background:#fffff6"><?php echo htmlspecialchars(@$icerik); ?></textarea> | |
<?} ?> | |
</body> | |
</html> |
teşekkürler. bunun javascript için olanı var mı?
@akcansoft maalesef. Fakat esas olay strtr
satırından başlayan karakter değişimlerinden ibaret. Dolayısıyla kolaylıkla JS versiyonu yazılabilir.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Çok işime yaradı gerçekten teşekkürler!