0

I want to read data from a .txt file using php. I want to show data in one column but I am unable.

My file.txt contain this data:

ہو
تو
کر
جو
نہ

And I'm getting output like this:

ہو 㰊牢>تو 㰊牢>کر 㰊牢>جو 㰊牢>نہ 㰊牢>؟ 㰊牢>ہیں 㰊牢>ان 㰊牢夾畯栠癡⁥湡攠牲
<?php

$conn = mysql_connect("localhost","root",""); 
mysql_select_db("Project",$conn);
mysql_query("SET NAMES UTF8");
$handle = @fopen("file.txt", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 1024); 
    list($urdu)=explode('/n',$buffer);

    echo $urdu."<br>";

    $sql = "INSERT INTO fb (urdu) VALUES('$urdu')";
    mysql_query($sql) or die(mysql_error());
}

So please tell me how can display text like this:

ہو
تو
کر
جو
نہ
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

Problem seems to be from an encoding mismatch, so first figure out where this mismatch is occurring, your problem could be:

a) your php code could be reading input using an incorrect encoding (if you are trying to read in iso-8859, but the source file is encoded some other way)

b) your php code could be writing output using an incorrect encoding

c) whatever you are using to read the output (your browser) could be set to a different encoding than the bytes you are writing.

So once you figure out which of the 3 places is causing your problem, you can figure out how to fix it by understanding what your source encoding is, and how to read/write using that source encoding instead of another encoding (which your system has probably set as the default).

Maybe you can use mb_detect_encoding and mb-convert-encoding.

Just_Do_It
  • 821
  • 7
  • 20