From bec76cab71e6e61fcb8e02de6d1a6bb6890b92a7 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 25 Jan 2004 13:03:24 +0000 Subject: [PATCH] Update examples --- ext/spl/examples/findfile.inc | 25 ++++++++++++++++++++++ ext/spl/examples/findfile.php | 15 +------------ ext/spl/examples/findregex.php | 39 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100755 ext/spl/examples/findfile.inc create mode 100755 ext/spl/examples/findregex.php diff --git a/ext/spl/examples/findfile.inc b/ext/spl/examples/findfile.inc new file mode 100755 index 0000000000..e0c685b659 --- /dev/null +++ b/ext/spl/examples/findfile.inc @@ -0,0 +1,25 @@ +file = $file; + parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } + + function accept() + { + return !strcmp($this->current(), $this->file); + } +} + +?> \ No newline at end of file diff --git a/ext/spl/examples/findfile.php b/ext/spl/examples/findfile.php index 68c0e0dd65..0622c4e3d7 100755 --- a/ext/spl/examples/findfile.php +++ b/ext/spl/examples/findfile.php @@ -24,18 +24,5 @@ EOF; exit(1); } -class FindFile extends FilterIterator -{ - protected $file; - - function __construct($path, $file) { - $this->file = $file; - parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } - function accept() { - return !strcmp($this->current(), $this->file); - } -} - -foreach(new FindFile($argv[1], $argv[2]) as $pathname => $file) echo $file->getPathname()."\n"; +foreach(new FindFile($argv[1], $argv[2]) as $file) echo $file->getPathname()."\n"; ?> \ No newline at end of file diff --git a/ext/spl/examples/findregex.php b/ext/spl/examples/findregex.php new file mode 100755 index 0000000000..faed6a8ee0 --- /dev/null +++ b/ext/spl/examples/findregex.php @@ -0,0 +1,39 @@ + + * + * Path to search in. + * Filename to look for. + * + * (c) Marcus Boerger, Adam Trachtenberg, 2004 + */ + +if ($argc < 3) { + echo << + +Find a specific file by name. + + Path to search in. + Regex for filenames to look for. + + +EOF; + exit(1); +} + +class RegexFindFile extends FindFile +{ + function accept() + { + return preg_match($this->file, $this->current()); + } +} + +foreach(new RegexFindFile($argv[1], $argv[2]) as $file) { + echo $file->getPathname()."\n"; +} + +?> \ No newline at end of file -- 2.50.1