PHP - Accessing CSV file and printing specific cells on screen

Asked

Viewed 213 times

2

How to access a. CSV file via PHP and print a specific cell on the screen?!
Example:

Column A - Row 1
It is written: Alexander

How to take this cell from "A1" and print on the screen?!
I want to apply it to this DASHBOARD:

Example:

In the CSV has there "Planned: 5,000", I want to take this cell that says the plan of the day is 5,000 and put it on the Dashboard there, where the "null".

inserir a descrição da imagem aqui

1 answer

1

Hello,

The function that will help you in this case is the fgetcsv.

Official documentation: http://php.net/manual/en/function.fgetcsv.php

Example taken from official documentation:

<?php
$row = 1;
if (($handle = fopen("teste.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num campos na linha $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.