Posted By

iTony on 03/16/08


Tagged

csv spaces coma


Versions (?)

file spaces to commas


 / Published in: PHP
 

  1. <?php
  2.  
  3. $handle = @fopen("data.txt", "r");
  4.  
  5. if ($handle)
  6. {
  7. while (!feof($handle))
  8. {
  9. $buffer = fgets($handle, 4096);
  10. // this will search for 5 spaces and replace with 1, then 4, then 3, then 2
  11. // then only one will be left. Replace that one space with a comma
  12. // then output with nl2br so you can see the line breaks
  13.  
  14. print nl2br(str_replace(" ", ",",ereg_replace( ' ', ' ',ereg_replace( ' ', ' ', ereg_replace( ' ', ' ', ereg_replace( ' ',' ',$buffer ))))));
  15. }
  16. }
  17.  
  18. fclose($handle);
  19. ?>

Report this snippet  

You need to login to post a comment.