How to Display Data from CSV file using PHP ? Last Updated : 14 Dec, 2020 Comments Improve Suggest changes Like Article Like Report We have given the data in CSV file format and the task is to display the CSV file data into the web browser using PHP. To display the data from CSV file to web browser, we will use fgetcsv() function. Comma Separated Value (CSV) is a text file containing data contents. It is a comma-separated value file with .csv extension, which allows data to be saved in a tabular format. fgetcsv() Function: The fgetcsv() function is used to parse a line from an open file, checking for CSV fields. Execution Steps: Open XAMPP server and start apache serviceOpen notepad and type the PHP code and save it as code.phpStore the CSV file in the same folder. Like xampp/htdocs/gfg/a.csvGo to browser and type http://localhost/gfg/code.php. Filename: code.php PHP <!DOCTYPE html> <html> <body> <center> <h1>DISPLAY DATA PRESENT IN CSV</h1> <h3>Student data</h3> <?php echo "<html><body><center><table>\n\n"; // Open a file $file = fopen("a.csv", "r"); // Fetching data from csv file row by row while (($data = fgetcsv($file)) !== false) { // HTML tag for placing in row format echo "<tr>"; foreach ($data as $i) { echo "<td>" . htmlspecialchars($i) . "</td>"; } echo "</tr> \n"; } // Closing the file fclose($file); echo "\n</table></center></body></html>"; ?> </center> </body> </html> Output: Comment More infoAdvertise with us S sravankumar_171fa07058 Follow Improve Article Tags : PHP HTML-Misc PHP-Misc Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like