Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $login = "login"; // Fill in your username / customerid
- $password = "password"; // Fill in your password
- $filename = "URL";
- // Get the pricelist into an array.
- $lines = file( $filename ); // personally I would suggest file_get_contents()
- // Create CSV header (first row)
- $fields = array(
- "sku",
- "stock"
- );
- // Create CSV file
- $csv_file = fopen( "output.csv", "w" );
- fputcsv( $csv_file, $fields );
- // Loop through our array
- foreach ( $lines as $line_num => $line ) {
- echo "Line #<b>{$line_num}</b> : " . htmlspecialchars( $line ) . "<br /><br />";
- $column = explode ( '"~"', $line ); // use the "~" as explode char
- echo $column[0] . " productid <BR>";
- echo $column[1] . " stock <BR>";
- // $column[1] is assumed to the stock level and contains y or n
- if( strtolower( $column[1] ) == "y") {
- $column[1] = 99; // has stock
- } else {
- $column[1] = 0; // wasn't a "y" so no stock for you sir
- }
- // etc
- $fields = array(
- $column[0],
- $column[1]
- );
- // stuff into a csv file
- fputcsv($csv_file, $fields);
- }
- // Be nice and close CSV file
- fclose($csv_file);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement