webent Posted June 24, 2008 Share Posted June 24, 2008 Does anyone know of a way to parse a csv file, via php of course, that's tab delimited? Here's what I am using, but it's still messing up... <? // Side note... there are 22 columns, not sure if I can use that data anywhere to ensure that it stops reading after that many columns... $row_counter = 0; $handle = fopen("http://get-in-trouble-if-i-show.com/blah/vendor_export.php?use_link=on&ve_sid=505oyt8qdnq6d409m0vumxa0x5wu3itx", "r"); while (($fields = fgetcsv($handle, 0, " ", ",")) !== FALSE) { $row_counter++; if ($row_counter == 1) { // First row header removed. } else { // Remove apostrophes $search = array("'"); $replace = array(""); $fields = str_replace($search,$replace,$fields); echo $fields[0] . '<br>'; } } fclose($handle); ?> Just doing the error checking now, once I see that all the fields are proper, then I'll be looping it in a db... So, as you can see, I'm using " " and "," but I'm not sure how to tell it to look for "tabs" ... Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/111677-solved-csv-parsing-by-tab-delimited/ Share on other sites More sharing options...
kenrbnsn Posted June 24, 2008 Share Posted June 24, 2008 The third parameter to fgetcsv is the delimiter, so you should use "\t" for a tab. You probably don't want to use the fourth parameter since that is for the string enclosure and that defaults to the double quote: <?php while (($fields = fgetcsv($handle, 0, "\t")) !== FALSE) { ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/111677-solved-csv-parsing-by-tab-delimited/#findComment-573232 Share on other sites More sharing options...
webent Posted June 24, 2008 Author Share Posted June 24, 2008 Worked like a charm, thank you very much kenrbnsn Quote Link to comment https://forums.phpfreaks.com/topic/111677-solved-csv-parsing-by-tab-delimited/#findComment-573235 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.