SomniusX

Read CSV

Mar 20th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. /********************** READCSV ********************** START        */
  2. $sbkfile = fopen($_SERVER['DOCUMENT_ROOT'] . '/includes/sbk.php', 'r'); //  fopen csv file
  3. $header = fgetcsv($sbkfile);                // get the first (header) line
  4. $data = array();                            // get the rest of the rows
  5. while ($row = fgetcsv($sbkfile)) {          // while loop for file
  6.   $arr = array();                           // setting array variable
  7.   foreach ($header as $i => $col)           // foreach loop about columns
  8.     $arr[$col] = $row[$i];                  // setting things straight
  9.   $data[] = $arr;                           // setting $data variable from array
  10.     array_unshift($data,"");                // shift array from base 0 to base 1
  11.     unset($data[0]);                        // unsetting array level 0 which now is lifted to 1
  12. }
  13. /********************** READCSV ********************** END      */
Advertisement
Add Comment
Please, Sign In to add comment