View Single Post
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

how to delete extra commas on csv file with php

 
0
  #1
Jun 11th, 2008
Hello I have this csv file


414060,440A,,,"QUECHAN INDIAN TRIBE SECRETARY- HIGHER EDUCATION DEPARTMENT Salary $8.00 per hour Position Closes May 9th, 2008 Position is responsible for providing administrative support to the Higher Education Department. Preparing office reports, maintaining the fi"
414297,445B,,," Come work in a great team environment. NOW HIRING FT Activities Assistant Ask for Elga Martinez FT HOUSEKEEPER Benefits available. Inquire within. 2222 S. Ave A., Yuma Ask for Theresa Cardenas"
411963,470A,,,x x x x x x x x
413675,470A,,,"NEWSPAPER DELIVERY Arizona Republic has opening for newspaper delivery to homes and store accounts. Must have reliable auto, early morning hours, approximately 3 1/2 hours, 7 days per week. Earn $800 - $1,000 monthly. For more information call 928-344-60"
414041,470A,,,"COUPLE WANTED to manage & maintain well kept, 146 space, Yuma RV Resort. F/T, Residence & Salary 928-782-2222"

With this php file I am writting the headers to this csv file so it can be parse into xml

  1.  
  2. <?php
  3.  
  4.  
  5. $new_line = 'ID, Category, Description'."\n";
  6.  
  7. $file = 'dtifeed.csv';
  8.  
  9. $old_lines = file($file);
  10.  
  11. array_unshift($old_lines,$new_line);
  12.  
  13. $new_content = join('',$old_lines);
  14. $fp = fopen($file,'r+');
  15.  
  16. $write = fwrite($fp, $new_content);
  17. fclose($fp);
  18.  
  19.  
  20.  
  21.  
  22.  
  23. $row = 1;
  24. $handle = fopen("dtifeed.csv", "r+");
  25.  
  26.  
  27. while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  28. $num = count($data);
  29.  
  30. $row++;
  31. for ($c=0; $c < $num; $c++) {
  32. echo $data[$c] . "<br />\n";
  33.  
  34. }
  35. }
  36.  
  37.  
  38.  
  39.  
  40. fclose($handle);
  41.  
  42.  
  43. ?>

My problem is the extra commas in the csv before the descrption, How could I delimit just to 1 comma before the description on each ad with php?

Thank you
Reply With Quote