cluce Posted June 29, 2007 Share Posted June 29, 2007 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? Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 29, 2007 Share Posted June 29, 2007 I've never tried using csv files with php, but that may be the problem. Quote Link to comment Share on other sites More sharing options...
cluce Posted June 29, 2007 Author Share Posted June 29, 2007 actually csv file are the only type of files I can get to display right. well some csv files does and some dont. I am thinking it might be the data in the file that screwed up???? Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 29, 2007 Share Posted June 29, 2007 perhaps.. Have you tried creating a test file to see what happens. It may be that new files will be okay and the old files are somehow corrupt. Quote Link to comment Share on other sites More sharing options...
per1os Posted June 29, 2007 Share Posted June 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
cluce Posted June 29, 2007 Author Share Posted June 29, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.