0

Hello,
Im trying to store 4 rows of delimited text from a text file(
abc, abc, abc, abc
abc, abc...
...
...)
into an array and loop each line of the array
and print it, but its not going well.

<?
$file1 = "properties.txt";
$filedata = fopen($file1,"r");
$array1 = file ($file1);
$file2 = gettext($array1, 1);
//forget the loop for now
for ($count1 = 0; $count1 < count($array1); $count1++ )
{ 
$line1 = $array1[$count1];
}

print "$array1  $file2";
exit;

function gettext ($text)
{
$array2 = explode(",", $text);
return $array2;
}
?>

Edited by ethio: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0

Hello, first of all you are using $filedata without needing it. Line 5 : gettext($array1, 1); . As understood your function gettext can take one argument but you are sending two. If it is a two dimensional table (csv) than it is a two dimensional array as well (if you want to store the values in one array).

0

You just need to explode with "\n". Then you get four lines.

$str = file_get_contents($file);
$lines = explode("\n",$str);
foreach($lines as $line){
  echo $line . "<br />";
}

From your description, you wanted to print/echo lines, correct?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.