Page 1 of 1

Reading from a file

Posted: Wed Mar 30, 2005 12:01 am
by radar
Does anyone know of a way to get php to read a file and then out put it into an array like:

$var[1][2]

where 1 is the line number and 2 is the word? Thanks.

Reading from a file

Posted: Wed Mar 30, 2005 4:46 am
by Josh

Code: Select all

<?php

$lines = file("news_system.ffd");

foreach($lines as $key => $val) 
{  
   $data[$key] = explode("||", $val);
}

for($q = 0; $q < sizeof($lines); $q++) 
{ 
   echo $data[$q][0];
   echo $data[$q][1];
   echo $data[$q][2];
}

?>
There's a snippet from my flat file db news script, but this is only putting the different data from the file into an array..... I guess you could try and modify this to get what you're looking for though

Reading from a file

Posted: Wed Mar 30, 2005 2:04 pm
by radar
To get it to explode on the space though so it gives each word... what's the character for space? it's not " "

Reading from a file

Posted: Wed Mar 30, 2005 2:42 pm
by Josh
Where there's char 32 and char 106.... 32 is the more used though.. not sure what's so special about 106 though.