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
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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.