[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
PhpArray
This snippet shows how to read a text file line by line and create an array of lines to represent the read file.
This example has been taken from http://www.snippetcollection.com
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
PhpArray
(PHP) Array
<?php
// file example 1: read a text file into an array, with
// each line in a new element
$filename="input.txt";
$lines = array();
$file = fopen($filename, "r");
while(!feof($file)) {
//read file line by line into a new array element
$lines[] = fgets($file, 4096);
}
fclose ($file);
print_r($lines);
?> This snippet shows how to read a text file line by line and create an array of lines to represent the read file.
This example has been taken from http://www.snippetcollection.com
<?php
//file example 2: this class reads a CSV file."comma delimited file" with four elements.
class stockdetails
{
//defines an array called allStock;
private $allStocks;
function __construct(){
}
//Method that processes the file, one line at a time.
function process_file($file_name){
$d_filecontent = file($file_name);
$i=0;
/*reads each line, then explodes the line into a list.
the elements in the list are then assigned into an 2 dimensional associative array
- /
Arrays in other languages
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
