Member Avatar for kirtan_thakkar

I have a text file and i want it to open and add all the line to an array. Which function is used in php for that task??

Which separator is used for a new line..??

Can any one help...

fgets — Gets line from file pointer

string fgets ( resource $handle [, int $length ] )
Gets a line from file pointer.

Example #1 Reading a file line by line

<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
Member Avatar for rajarajan2017
<?php 
$textfromfile = array();
$file = '..\library\para.txt' or die('Could not read file!'); 
$data = file($file) or die('Could not read file!'); 
foreach ($data as $line) { 
	array_push($textfromfile, $line);
     echo $line; 
} 
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.