Home >Backend Development >PHP Problem >How to convert text file to array class in php
In PHP, you can use the file() function to convert a text file into an array class. This function can store the contents of the entire file into an array line by line (including newlines); the syntax "file( $filename,$flags,$context)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use the file() function To convert text file to array class.
PHP file() can read the entire file into an array. This function will store the contents of the file into the array line by line (including newlines). This array is returned on success, FALSE on failure.
Syntax:
file($filename,$flags,$context)
Parameter description is as follows:
Example: Read the following file
<?php header("Content-Type: text/html;charset=utf-8"); //设置字符编码 $file = 'test.txt'; $filearr = file($file,FILE_IGNORE_NEW_LINES); var_dump($filearr); ?>
Output result:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert text file to array class in php. For more information, please follow other related articles on the PHP Chinese website!