Scanning files for a specific string

Wednesday, June 11th, 2008

Over at DevNetwork forums somebody asked for a piece of code, that scans a directory containing thousands of files for a file containg specific string. Here is the solution I came up with it: < ?php // list file extensions that you care about here $extensions = array('php','inc'); foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.')) as $Item) { ...

Searching file contents with Iterators

Wednesday, June 4th, 2008

// the following code returns all lines of source.txt that contain the string Aerosmith. // Feel free to extend it for your own uses class FileGrep extends FilterIterator { private $needle; public function __construct($file, $needle) { parent::__construct(new SplFileObject($file)); ...

SimpleXMLIterator & FilterIterator combined

Tuesday, June 3rd, 2008

< ?php /* Goal: * Take a GPX (which is XML) file * Extract interesting records from it * Calculate the arithmetic average of latitudes and longitutes ...