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

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.