Reading from a file

Support, Snippets & Projects

Moderators: Moderator, Global Moderator

Post Reply
radar
Hero Member
Hero Member
Posts: 632
Joined: Wed Jun 16, 2004 5:37 pm

Reading from a file

Post 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.
Josh
Hero Member
Hero Member
Posts: 4627
Joined: Fri Jun 04, 2004 7:54 am

Reading from a file

Post 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
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
radar
Hero Member
Hero Member
Posts: 632
Joined: Wed Jun 16, 2004 5:37 pm

Reading from a file

Post 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 " "
Josh
Hero Member
Hero Member
Posts: 4627
Joined: Fri Jun 04, 2004 7:54 am

Reading from a file

Post 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.
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Post Reply

Return to “PHP &amp; MySQL”