Array in file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Array in file

Post by Jose Arce »

Hi there, how can i convert the content of a file, to an element array, i mean, each line as an element...thanks :D!
Peter
Forum Commoner
Posts: 28
Joined: Mon Jun 10, 2002 12:40 am
Location: Brisbane, Australia

Post by Peter »

Try the function, file(). :)
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

you'll smack yourself after you see how easy it is ... :lol:

Code: Select all

$fileArray = file($filename)

http://www.php.net/manual/en/function.file.php
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

Thx...i'm trying to make a foreach loop with the array..but it send me this error message:
Warning: Invalid argument supplied for foreach() in /home/sites/site187/users/arcelio/web/script.php on line 82

How can i make a foreach script?
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

this would jsut print each line, but just do whatever you want with the line...

Code: Select all

$fileArray = file($filename);

foreach($fileArray as $line) {
	echo $line;
}
Jose Arce
Forum Commoner
Posts: 37
Joined: Wed May 01, 2002 5:05 pm

Post by Jose Arce »

all right!!!

Thx dude!
Post Reply