12-03-2008, 11:19 PM
|
#3 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
The only trouble with using file is that you're loading the entire file into memory. Much better is to read the file line by line and do with it what you want.
Here are two approaches using this line of thought.
Plain old fopen/fgets
PHP Code:
$file = fopen('dictionary.txt', 'r');
while ( ! feof($file))
{
$line = fgets($file, 1024);
list($word, $type, $definition) = explode(' ', rtrim($line), 3);
}
SPL File Object
PHP Code:
$file = new SplFileObject('dictionary.txt');
foreach ($file as $line)
{
list($word, $type, $definition) = explode(' ', rtrim($line), 3);
}
|
|
|
|