Jump to content

[SOLVED] when reading from file it displays the data all crazy looking????


cluce

Recommended Posts

when reading from file it displays the data all crazy looking and I am not sure why this is. Some files work and some don't. Can anybody shed some light on this??  I am pretty sure my code is right.

<?php
$filename = "AD.csv";
$fp = fopen($filename, "r") or die("Couldn't open $filename");
while (!feof($fp)) {
$line = fgets($fp, 1024);
echo $line."<br/>";
}
?>

I just would like to know whats going on.  here is an example of the output...);_(* "-"??_);_(@_)àõÿ À àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ àõÿ ôÀ à

Also, does this code only work on certain file types?

What file types are showing up bad, .xls? It seems like you are reading a binary file, which would be the reason for the garbled text. Remember you cannot read a binary file like that you have to have some type of a program/intrepretor. Such as .xls (excel) file provides a way to export the data as cvs so it can be easily read.

What file types are showing up bad, .xls? It seems like you are reading a binary file, which would be the reason for the garbled text. Remember you cannot read a binary file like that you have to have some type of a program/intrepretor. Such as .xls (excel) file provides a way to export the data as cvs so it can be easily read.

yes. thats what haappened.

 

But I did try reading doc, txt, and xls just to see what would happened and none of those worked. the only files I can read with php are the csv files and I have to actually save it as csv not just rename the file extension for it to work. I think I got it for now. thanks

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.