Skip to content

Instantly share code, notes, and snippets.

@jaytaph
Created January 6, 2011 11:39
Show Gist options
  • Save jaytaph/767793 to your computer and use it in GitHub Desktop.
Save jaytaph/767793 to your computer and use it in GitHub Desktop.
MyRegexIterator.php
<?php
class MyNewerRegexIterator extends RegexIterator {
public function accept() {
$current = $this->current();
if (! isset($current->item)) {
return false;
}
if (preg_match($this->getRegex(), $current->item)) {
return true;
}
return false;
}
}
<?php
class MyRegexIterator extends RegexIterator {
protected $_regex;
public function __construct($iterator, $regex, $mode, $flags, $preg_flags ) {
$this->_regex = $regex;
parent::__construct($iterator, $regex, $mode, $flags, $preg_flags);
}
public function getRegex() {
return $this->_regex;
}
public function accept() {
$current = $this->current();
if (! isset($current->item)) {
return false;
}
if (preg_match($this->getRegex(), $current->item)) {
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment