PDA

View Full Version : سوال: اينکود زمان خواندن زبان فارسي file_get_contents



hamid2007id
جمعه 07 شهریور 1393, 04:05 صبح
سلام

يک فايل txt قراره خوانده بشه و توش عنوان (نام شهر ) و لينک مشخص بشه

مثالي از اطلاعات داخل فايل :

www.example.com/about.html:مشهد (http://www.example.com/about.html:مشهد)
www.example.com/about2.html:تهران (http://www.example.com/about2.html:تهران)
www.example.com/about3.html:اصفهان (http://www.example.com/about3.html:اصفهان)

اگر اسم فينگليشي باشه خوب مشکلي نيست . ولي وقتي کاراکتر فارسي ( به عنوان مثال مشهد ) چکار کنم تا بدون بهم ريختگي در مرورگر نشان داده بشه






<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8>
</script>*************<script>
<link rel="stylesheet" type="text/css" href="samplecss.css>
<head/>





<?php

$cit = file_get_contents("cities.txt");
$cot = explode("\n",$cit);
foreach($cot as $city){

$city = explode(":",$city);
$name = $city[0];
$xml = $city[1].":".$city[2];
?>
<option id="city" value="<?=$xml?>"> <?=$name?> </option>
<?

}

?>

smksmk
جمعه 07 شهریور 1393, 18:56 عصر
سلام ، بستگی داره که روی سیستم شما فایل تکست با چه encoding ذخیره میشه ، در کل با mb_convert_encoding میتونید encoding رو تغییر بدین ، و با استفاده از mb_detect_encoding هم تشخیص بدین .



<?php
$cit = file_get_contents("cities.txt");
mb_convert_encoding($cit, 'UTF-8',mb_detect_encoding($cit, 'UTF-8, ISO-8859-1', true));
$cot = explode("\n",$cit);
echo '<select>';
foreach($cot as $city){

$city = explode(":",$city);
$name = $city[0];
$xml = $city[1].":".$city[2];
?>
<option id="city" value="<?php echo $xml; ?>"> <?php echo $name; ?> </option>
<?php

}
echo '</select>';
?>

smksmk
جمعه 07 شهریور 1393, 18:59 عصر
این هم فایل TEXT