$i = 0; // row counterforeach ($out as &$cur){ if ($i == 0) { $cvsHeadings = array_keys($cur); fprintf($fpo, chr(0xEF).chr(0xBB).chr(0xBF)); // writes file header for correct encoding. fputcsv($fpo, $cvsHeadings); // Write column headings to the file fputcsv($fpo, $cur); // first row will get missed out if we don't output it here } else { // now we have the headings in just add each row fputcsv($fpo, $cur); // Write information to the file } $i++;}
One that webpage it says that the error is due to not having the correct UTF-8 encoding.
Now my real question is whats going on here as i thought i was forcing UTF-8 encoding with this line in my code:
fprintf($fpo, chr(0xEF).chr(0xBB).chr(0xBF)); // writes file header for correct encoding.
The error doesn't give the row that the error is found on.
The CSV is 1936 rows and it only errors on 30 of them. I would have to post all 1936 rows. Do you want that?
i can give you a link to the script with an print_r(); if that will help?
I think i just need to force all the text in the CSV to use UTF-8 so that the importer can interpret the row correctly.
unless there is another reason why it would error? not sure.
UTF-8 is self-evident. If you want to give me a download link for the big CSV file, I will try to locate the UFT-8 errors with software and we can look at them. Or you might try looking in the UTF-8 article for Detecting JSON Errors because I think that technology can be applied to finding the errors in the CSV.
0
Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
Working on it now. Please remove the BOM bytes from the front of the output document. You don't want that. UTF-8 is self-evident. The byte-order mark is worse than useless unless the code at Magento cannot function without it (their documentation will tell you).
Please post back when I can get a copy of the CSV without the BOM, thanks.
I have to leave for a while now, and may be able to look at this again later. The script doesn't quite do all I want it to do yet, but at least it identifies the locations of the bad UTF-8 characters. I'll post back with more later. http://www.iconoun.com/demo/temp_helpchrisplz.php
Scroll down to line 749 to see an example of what is being detected.
oh i see: BYTE: 618, CHR: na ORD: 133, HEX: 85, BIN: 10000101
and it has question marks in the above row.
so that means we just need to update them rows to fix it.
When you say it doesn't quite do all I want it to do yet. What are you planning?
Is it possible to get a code example of how you managed to output this?
This will help me debug this if the client adds further bad characters in future.
More to follow. I cannot find a browser that can switch back and forth between ISO-8859-1 and UTF8 displays. They seem to be able to display either one or the other, but not both in the same request. So I can either show you the broken UTF-8 character or I can show you the original character. Need a bit more experimentation, I think.
I'll post a code sample after I get it refined a bit more.
This is not "demonstration quality" code, but it gets the job done. A few notes...
Line 14-15: Choose your output encoding.
Line 26-31: Try to fix any UTF-8 errors.
Line 34-46: See if the fix worked.
Line 49-end: Row-by-row and byte-by-byte verification of the encoding.
Line 45 should be changed to write the converted file back to your server so it can be used in your application.
// WITH EACH ROW OF THE CSV FILEforeach ($txt as $row => $str){///// i have commented out your formating// echo PHP_EOL . "ROW: " .str_pad($row, 4, ' ', STR_PAD_LEFT); // echo ' ' . $str;//// make a new line echo $str."\n";
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.