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;
}
?>

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).

Member Avatar for diafol

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?

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.