Jump to content

fread() Showing Strange Characters In Data


l4nc3r

Recommended Posts

I'm creating a program that will parse an uploaded csv file, but I keep getting these strange characters within the data.  If I re-save the file in MS Excel, it works fine, but I need the originals to work.

 

The only differences between the two are the " it inserts before/after each row and the attributes property of the new file (in right click > properties > details) is just A, where in the original it's AN.  What does that mean?

 

Here's the code:

 

...
$report_resource = fopen($_FILES['report']['tmp_name'], 'r');
echo fread($report_resource,filesize($_FILES['report']['tmp_name']));
while ($report_data = fgetcsv($report_resource, '', ',')) {
  ...
}
...

 

Which outputs:

 

e�x�t�b�o�x�2�,�t�e�x�t�b�o�x�3�,�X�A�_�T�r�a�n�A�m�t�_�1�,�X�A�_�R�S�B�a�l�a�n�c�e�_�1�,�X�A�_�R�S�P�o�i�n�t�s�_�1�,

 

It has the data there, it's just garbled by the ? characters.

 

What's happening? Any help much appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/95230-fread-showing-strange-characters-in-data/
Share on other sites

UTF encoded (2-byte chars)

 

<?php
$str = "e�x�t�b�o�x�2�,�t�e�x�t�b�o�x�3�,�X�A�_�T�r�a�n�A�m�t�_�1�,�X�A�_�R�S�B�a�l�a�n�c�e�_�1�,�X�A�_�R�S�P�o�i�n�t�s�_�1�,";
$k = strlen($str);
$res = '';
for ($i=0; $i<$k; $i+=2) $res .= $str[$i];
echo $res;
?>
--> extbox2,textbox3,XA_TranAmt_1,XA_RSBalance_1,XA_RSPoints_1, 

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.