In this PHP tutorial, We will learn how to read any text/xml file line by line and store it in the database. We will use PHP back-end language for reading and storing data in DB.
A file is simply a resource for storing information on a computer.
Usually, files are used to hold information like:
PHP provides set of in-built functions to handle files. Some of the functions are, fopen()
, file_exists()
, file_get_contents()
and etc.
The following list includes some of the fundamental file-related operations.
The file() method is used to read an entire file into an array. Each array element contains a line from the file with the newline character.
Syntax:
file(filename, flag, context)
Check out other tutorials of PHP File,
The file()
methods to read any text/xml file into an array. We will use this method and read the file line by line. The following code snippet is used for read the file.
$lines = file('test.txt'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "Line #{$line_num} : " . htmlspecialchars($line) . "\n"; }
You can download source code from the below link.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More