Search results
3 wrz 2009 · use the file() function - easy! $lines=file('file.txt'); If you want to do some processing on each line, it's not much more effort to read it line by line with fgets()...
27 lip 2016 · $arr = array('name','rollno','address'); file_put_contents('array.txt', json_encode($arr)); Then, when you need it: $my_arr = json_decode(file_get_contents('array.txt'), true); echo $my_arr[1]; // rollno
The file() reads a file into an array. Each array element contains a line from the file, with the newline character still attached. Syntax
The file() function reads an entire file specified by a $filename into an array: The file() function has three parameters: $filename is the path to the file. $flags is an optional parameter that can be one or more of the constants below. $context is a valid stream context resource.
The file() function in PHP is used to read the contents of a file into an array. Each line of the file is stored as an element in the array. The following code reads the contents of the myfile.txt file into an array: $lines = file('myfile.txt'); The code then loops through the lines of the file and trims any whitespace from each line:
Reads an entire file into an array. Note: You can use file_get_contents() to return the contents of a file as a string.
13 lis 2023 · Read file into a string – $contents = file_get_contents("FILE"); Read file into an array – $array = file("FILE"); Use cURL to fetch a file from a different server.