Advertisement
moggiex

Collect file and apply process logic

Oct 28th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1. <?php
  2.  
  3. $login      = "login";      // Fill in your username / customerid
  4. $password   = "password";   // Fill in your password
  5. $filename   = "URL";
  6.  
  7. // Get the pricelist into an array.
  8. $lines = file( $filename );     // personally I would suggest file_get_contents()
  9.  
  10. // Create CSV header (first row)
  11. $fields = array(
  12.     "sku",
  13.     "stock"
  14. );
  15. // Create CSV file
  16. $csv_file = fopen( "output.csv", "w" );
  17. fputcsv( $csv_file, $fields );
  18.  
  19. // Loop through our array
  20. foreach ( $lines as $line_num => $line ) {
  21.  
  22.     echo "Line #<b>{$line_num}</b> : " . htmlspecialchars( $line ) . "<br /><br />";
  23.     $column = explode ( '"~"', $line ); // use the "~" as explode char
  24.     echo $column[0] . " productid <BR>";
  25.     echo $column[1] . " stock <BR>";
  26.    
  27.     // $column[1] is assumed to the stock level and contains y or n
  28.    
  29.     if( strtolower( $column[1] ) == "y") {
  30.         $column[1] = 99;    // has stock
  31.     } else {
  32.         $column[1] = 0;     // wasn't a "y" so no stock for you sir
  33.     }
  34.    
  35.     // etc
  36.     $fields = array(
  37.         $column[0],
  38.         $column[1]
  39.     );
  40.    
  41.     // stuff into a csv file
  42.     fputcsv($csv_file, $fields);
  43. }
  44. // Be nice and close CSV file
  45. fclose($csv_file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement