-1

How to read Unicode text file in PHP. i have used HTML tag <meta http-equiv="content-type" content="text/html; charset=utf-8">. i have some content in 15.txt like.

جوڈیشنل کمیشن کا کاروائی کھلی عدالت میں جاری رکھنے کا فیصلہ ; پانچ مئی کو شہادتوں پر جرح کا آغاز کیا جائیگا

but this code print this type (ÿþEÌ1' F'E 9E1'F ÁÒ)

i want to print Urdu contents, plase tell me where i am wrong

$row = 1;
$myFile = 15.txt; // Unicode Formate. 
if (($handle = fopen($myFile, "r")) !== FALSE){
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { 
    $num = count($data); 
    $row++;
    $row1 = $data[0];
    $row2 = $data[1];   

    echo '<h1>'.$row1.'</h1>';
    }


    fclose($handle); 

} else {
    echo "Error deleting record: " . $conn->error;
}

when i show

Imran Hafeez
  • 62
  • 10

2 Answers2

0

please use header to modify your text you need to put header commant top of the page you server default language might be english so it cannot show your local language. so we need to use header and set charset to utf-8. Also Turkish Users have same problem because we use some special character like this "ş,ı,ü,ğ,ç,ö" we need to set charset utf-8 to see our text correctly

header('Content-Type: text/html; charset=utf-8');

Also if you have same problem when you get data from db you need to convert utf 8 your data

mysql_query("SET NAMES utf8");
Ahmet ATAK
  • 342
  • 2
  • 13
0

Make sure you are using UTF-8 charset everywhere:

Firstly:

<?php header("Content-type: text/html; charset=utf-8"); ?>

Then in your connection instance:

for PDO-> $conn->exec("set names utf8");

for Mysqli-> $conn->set_charset("utf8");

also worth mentioning, for Mysql->mysql_set_charset('utf8');

And make sure that your table's collation is: utf8_general_ci (which should be by default).

hatef
  • 5,491
  • 30
  • 43
  • 46