TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-02-2009, 12:18 AM   #1 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default help with fscanf

I have to read a very large text file with PHP (about 1 million lines and 45.4 MB) and speed is critical. The file is layed out like so.

Notice the extra space before and after each line

Code:
 {"one":1727294,"two":2667541,"three":9998168} 
 {"one":7005310,"two":9377441,"three":4658508} 
 {"one":2638549,"two":7931823,"three":992431} 
 {"one":8817443,"two":1587524,"three":6495056} 
 {"one":5009765,"two":4831848,"three":2782592} 
 {"one":9882507,"two":4866943,"three":7389221} 
 {"one":7161254,"two":281677,"three":9001464} 
 {"one":6177062,"two":661010,"three":4880065} 
 {"one":850830,"two":5882873,"three":4219360} 
 {"one":5865173,"two":8852539,"three":6194152}
Obviously, the file is too large to just load the entire thing into PHP so I'm using fscanf to read the file line by line.

Right now I have it so I can select an entire line if I know the whole thing. Here is what I got for that:

PHP Code:
while($data fscanf($fh,"\n{\"one\":1054687,\"two\":8728332,\"three\":2499389}%s\n"))
{
    
print_r($data);

What I want to do is be able to select one entire line with only knowing part of it (ex: "three":4219360). I'm not sure how to go about doing this because I have very little experience with fscanf and function of the like. I've tried something like this but it returns all of the rows:

PHP Code:
while($data fscanf($fh,"\n%s\"three\":2499389%s\n"))
{
    
print_r($data);

I do NOT want to have to load every line into PHP and check it that way as that could be very slow.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:24 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design