*/ /** * patTemplate modifier Explode * * Explode using delimiter and return part of array as index * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Explode extends patTemplate_Modifier { /** * Explode * * @param string value * @param array $params * @return string modified value */ public function modify( $value, $params = array() ) { if (empty($value)) { return $value; } if (!is_array($params)) { $params = array(); } $default = array( 'delimiter' => '/', 'index' => 0 ); $params = array_merge($default, $params); // nothing to do if (empty($params['delimiter'])) { return $value; } //$params['index'] = intval($params['index']); $value = explode($params['delimiter'], $value); $value = $value[$params['index']]; return $value; } }