How to Display Data from CSV file using PHP ? Last Updated : 14 Dec, 2020 Comments Improve Suggest changes 1 Likes 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: Create Quiz Comment S sravankumar_171fa07058 Follow 1 Improve S sravankumar_171fa07058 Follow 1 Improve Article Tags : PHP HTML-Misc PHP-Misc Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like