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 Next Article How to Display Data from CSV file using PHP ? S sravankumar_171fa07058 Follow Improve Article Tags : PHP HTML-Misc PHP-Misc Similar Reads How to Extract Data from an XML File Using PHP ? XML, which stands for Extensible Markup Language, is a data storage format that is easily searchable and understandable. It simplifies the process of storing, retrieving, and displaying data in informative applications. It is widely used in web applications. In this article, we will learn how to ext 3 min read How to retrieve data from MySQL database using PHP ? There are steps to understand for retrieving the data from the MySQL database. Approach: Create the database, then create the table for data.Enter the rows in the table. You have to connect to the database. Now we understand each and every step as shown below.  Example 1: In this. we use PHPMyAdmin 2 min read How to generate an XML file dynamically using PHP? A file can be generated using PHP from the database, and it can be done by the static or dynamic method in PHP. Static methods can be called directly - without creating an instance of a class. Here we are going to discuss how to create an XML file dynamically.The first thing we need to do is fetch t 2 min read How to generate PDF file from external text files using PHP ? In this article, we will learn how to generate PDF files from external text files with PHP by using FPDF. It is a free PHP class that contains many functions for creating and modifying PDFs. The FPDF class includes many features like page formats, page headers, footers, automatic page break, line br 5 min read How to create a table in PDF file from external text files using PHP ? In this article, we will learn to create a table in a PDF file from an external text file with PHP by using FPDF. It is a free PHP class that contains many functions for creating and modifying PDFs. The FPDF class includes many features like page formats, page headers, footers, automatic page break, 3 min read Like