class myFilter {
static private $exclusions;
static private $excluded;
static private $value;
public function __construct(Array $exclusions) {
self::$exclusions = $exclusions;
}
static function check($f, $v) {
return ($f and !(self::$value >= $v[0] and self::$value <= $v[1]));
}
static function getFilter($val) {
self::$value++;
if ( !array_reduce(self::$exclusions, "myFilter::check",true) ) {
array_push(self::$excluded, $val);
return false;
} else
return true;
}
public function getExcluded() {
return implode( ' ', self::$excluded );
}
public function reduce($str) {
self::$value = -1;
self::$excluded = [];
return implode( ' ', array_filter(explode(' ', $str), "myFilter::getFilter" ) );
}
}
$f = new myFilter ( [[2,2],[15,39],[78,78],[15,39],[154,154]] );
$text = $f->reduce($text);
echo $f->getExcluded();