function getcsv($filename, $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename))
return FALSE;
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
#notification {
animation-name: fadeOut;
animation-duration: 5s;
}
@keyframes fadeOut {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
function readCSV($csvFile){ // name the function and set the parameter
$file_handle = fopen($csvFile, 'r'); // open the csv file
while (!feof($file_handle) ) { // loop through the csv file
$line_of_text[] = fgetcsv($file_handle, 1024); // extract each line of the csv file
}
fclose($file_handle); // close the csv file
return $line_of_text; // return the array
}
// Set path to CSV file
$csvFile = 'test.csv';
$csv = readCSV($csvFile); // output the result of the function
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
/http:\/\/w{3}\.(\w+\.\w+)\//
<?php
$csv = array_map('str_getcsv', file('movies.csv'));
foreach($csv as $row)
{
echo "<pre>";
print_r($row);
echo "</pre>";
}
?>
<?
$row = 1;
$array = array();
if (($handle = fopen("file.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
$array[$row][$c] = $data[$c];
}
}
fclose($handle);
}
?>
function readCsv($fileName) {
$file = fopen($fileName, 'r');
$header = fgetcsv($file);
while($row = fgetcsv($file)) {
$rows[] = $row;
}
fclose($file);
return $rows;
}
<?php
$filename = 'data.csv';
$csv = array_map('str_getcsv', file($filename));
array_walk($csv, function(&$a) use ($csv) {$a = array_combine($csv[0], $a);});
array_shift($csv); # remove column header
foreach ($csv as $row) {
$company_name = $row['Company Name'];
$first_name = $row['First Name'];
$last_name = $row['Last Name'];
}
?>
function get_csv() {
$file = fopen("data.csv","r");
while(! feof($file)) {
$data[] = fgetcsv($file);
}
fclose($file);
return $data;
}
function loop_csv() {
$data = get_csv();
$count = count($data);
for ($x=1; $x<$count; $x++) {
echo $data[$x][0].", ".$data[$x][1].", ".$data[$x][2]."<br>";
}
}
loop_csv();
$file = fopen("data.csv","r");
while(! feof($file))
{
$array[] = fgetcsv($file);
}
fclose($file);
while (list($key, $value) = each($array)) {
echo $value[2];
}
<?php
$data = '{"name": "john", "age": 20}';
$csv = json_to_csv($data);
.popup {
/* Set the position of the popup box */
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* The actual popup */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border
<?php
$file = "./test.csv";
$csv = array_map('str_getcsv', file($file));
array_shift($csv);
print_r($csv);
?>
$file = fopen("test.csv", "r");
while(!feof($file)) {
$data[] = fgetcsv($file);
}
fclose($file);
print_r($data);
$filename = 'index.csv';
if(!file_exists($filename)) {
echo "The file $filename does not exist";
} else {
$file = fopen('index.csv', 'r');
while(($csv = fgetcsv($file)) !== false):
$line = implode(",", $csv);
$line = str_replace('"', '', $line);
$csv = explode(",", $line);
// do somethings with $csv
endwhile;
fclose($file);
}
function import_csv($csv_file_path) {
$csv_array = array_map('str_getcsv',file($csv_file_path));
unset($csv_array[0]);
foreach($csv_array as $csv) {
// do something with the CSV
}
}