$location_name) { $location_headers .= ',"location_' . $location_name . '"'; } return $location_headers; } /** * Generates a list of attribute names as a string * * @return string Comma-separated list of attribute names */ function generate_attribute_headers($attribute_names) { $attribute_headers = ""; unset($attribute_names[-1]); foreach($attribute_names as $attribute_name) { $attribute_headers .= ',"attribute_' . $attribute_name . '"'; } return $attribute_headers; } /** * Read the contents of a given CSV formatted file into a two-dimensional array * * @param string $file_name Name of the file to read. * @return boolean|array[][] two-dimensional array with the file contents or FALSE on failure. */ function get_csv_file($file_name) { ini_set("auto_detect_line_endings", true); if(($csv_file = fopen($file_name,'r')) !== FALSE) { //Skip Byte-Order Mark if(bom_exists($csv_file) === TRUE) { fseek($csv_file, 3); } while (($data = fgetcsv($csv_file)) !== FALSE) { //Skip empty lines if(array(null) !== $data) { $line_array[] = $data; } } } else { return FALSE; } return $line_array; } /** * Checks the first three characters of a file for the Byte-Order Mark then returns the file position to the first character. * * @param object $file_handle File handle to check * @return bool Returns TRUE if the BOM exists and FALSE otherwise. */ function bom_exists(&$file_handle) { $str = fread($file_handle,3); rewind($file_handle); $bom = pack("CCC", 0xef, 0xbb, 0xbf); if (0 === strncmp($str, $bom, 3)) { return TRUE; } else { return FALSE; } } ?>