What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Searching text files

Searching text files
Author: Message:
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Searching text files
quote:
Originally posted by -dt-

its even easier than that...

php code:
<?php

$dir = "D:/";
$toFind = "xxx";

foreach(new DirectoryIterator($dir) as $file){
    if(!$file->isDir()){
        $ext = trim(strrchr($file, '.'), ".");
        if($ext == "txt"){   
            $fp = fopen($file->getPathname(), 'r');
            while($fp && !feof($fp)){
                $line = stream_get_line($fp, 2048, "\n");
                if(strpos($line, $toFind) !== false){
                    echo $file . "\n";
                }
            }
            fclose($fp);
        }
    }
}
?>

Very elegant, I never thought of using foreach to work through each file or even stream_to_get_line! The more you use the more you learn!

This post was edited on 05-04-2009 at 12:35 AM by stoshrocket.
formerly methos
05-04-2009 12:35 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Searching text files - by Jimbo on 05-02-2009 at 03:45 PM
RE: Searching text files - by blessedguy on 05-02-2009 at 03:50 PM
RE: Searching text files - by Jimbo on 05-02-2009 at 04:18 PM
RE: Searching text files - by Baggins on 05-02-2009 at 04:55 PM
RE: Searching text files - by stoshrocket on 05-02-2009 at 07:15 PM
RE: Searching text files - by blessedguy on 05-02-2009 at 07:20 PM
RE: Searching text files - by Jimbo on 05-02-2009 at 07:30 PM
RE: Searching text files - by L. Coyote on 05-02-2009 at 08:05 PM
RE: Searching text files - by Jarrod on 05-02-2009 at 10:12 PM
RE: Searching text files - by WDZ on 05-03-2009 at 01:01 AM
RE: Searching text files - by Jimbo on 05-03-2009 at 05:45 PM
RE: Searching text files - by stoshrocket on 05-03-2009 at 07:27 PM
RE: Searching text files - by -dt- on 05-04-2009 at 12:15 AM
RE: Searching text files - by stoshrocket on 05-04-2009 at 12:35 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On