View Single Post
Old 03-02-2009, 01:11 AM   #2 (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

If you're after just a simple search, you could use fgets to grab the line and strpos to search it.

PHP Code:
// line: {"one":8405219,"two":4552659,"three":6640965}
$search '"three":6640965';

$fp fopen('misc.txt''r');

$result 'No result';
while( ! 
feof($fp))
{
    
$line fgets($fp70);
    if (
strpos($line$search) !== FALSE)
    {
        
$result trim($line);
        break;
    }
}
fclose($fp);

echo 
$result
For me, searching through a 46MB file with lines like yours took under two seconds to not find a match (worst case scenario).
Salathe is offline  
Reply With Quote