View Single Post
Old 12-03-2008, 11:19 PM   #3 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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($file1024);
    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);

Salathe is offline  
Reply With Quote