*/ /** * patTemplate modifier Tail * * Parameter: * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Tail extends patTemplate_Modifier { /** * modify the value * * @param string value * @param array list of parameter * @return string modified value */ public function modify($value, $params = array()) { $params = array_merge(array( 'start' => 1, 'lines' => 0, ), $params); $params['start'] = intval($params['start']); $params['lines'] = intval($params['lines']); $lines = explode("\n", $value); $cnt = count($lines); // start from top or bottom if (0 > $params['start']) { $params['start'] = max(array(0, $cnt + $params['start'])); } // start after the end? if ($cnt < $params['start']) { return ''; } $out = array(); for ($i = 0; $i < count($lines); ++$i) { if ($i > $params['start']) { continue; } $out[] = $lines[$i]; if (0 < $params['lines'] && $params['lines'] <= count($out)) { break; } } return implode("\n", $out); } }