Jump to content

File encoding problem


mraza

Recommended Posts

Hi, I have few files which i need to display in correct format and also save in db to use. My problem is here is my code:

$file =  "C:\\file.txt";
$data = file_get_contents($file);
$data = '<pre>';
$data .= mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1');
$data .= '</pre>';
echo $data;

 

but when i echo $data i get weird characters . here is result

http://paste2.org/p/1361878

 

Thanks for any help.

 

Link to comment
https://forums.phpfreaks.com/topic/233654-file-encoding-problem/
Share on other sites

You didn't change the encoding of the file data - just the filename.

 

$file = "C:\\file.txt";
$data = file_get_contents($file);
$data = mb_convert_encoding($data, "UTF-8", "ISO-8859-1");

// header("Content-Type: text/plain; charset=utf-8");
echo $data;

thanks for replies.

 

I tried both way but did not worked.

here is original file content

http://www.pastecode.info/view/29305328

 

and here is problem if i use above codes

http://www.pastecode.info/view/75500574

 

when i tried with htmlentities($data, ENT_QUOTES, "UTF-8"); i get cahrs like this and i had to use $data = mb_convert_encoding($data, "UTF-8", "ISO-8859-1"); or it just display blank page.

ßßßÿÿÿ

 

my code again:

$file = "C:\file.txt";
$data = file_get_contents($file);
// tried three of them one by one and together etc but same problem.
//$data = mb_convert_encoding($data, "UTF-8", "ISO-8859-1");
//$data = htmlentities($data, ENT_QUOTES, "UTF-8");
//header("Content-Type: text/plain; UTF-8");
echo $data;

thanks for any help.

Thanks but when i use above i get question marks

����������

 

my code

$file = "C:\file.txt";
$data = file_get_contents($file);
// tried with this too
// $data = mb_convert_encoding($data, "UTF-8", "ISO-8859-1");
header("Content-Type: text/html; charset=UTF-8");
echo $data;

 

also when i did detect i get UTF-8 Result

$data = file_get_contents($file);
echo mb_detect_encoding($data);
// echoed UTF-8

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.