matching pattern * 'replace' => replace with this * * @param string|array $options * @return void */ public function __construct($options = null) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } else if (!is_array($options)) { $options = func_get_args(); $temp = array(); if (!empty($options)) { $temp['match'] = array_shift($options); } if (!empty($options)) { $temp['replace'] = array_shift($options); } $options = $temp; } if (array_key_exists('match', $options)) { $this->setMatchPattern($options['match']); } if (array_key_exists('replace', $options)) { $this->setReplacement($options['replace']); } } /** * Set the match pattern for the regex being called within filter() * * @param mixed $match - same as the first argument of preg_replace * @return Zend_Filter_PregReplace */ public function setMatchPattern($match) { $this->_matchPattern = $match; return $this; } /** * Get currently set match pattern * * @return string */ public function getMatchPattern() { return $this->_matchPattern; } /** * Set the Replacement pattern/string for the preg_replace called in filter * * @param mixed $replacement - same as the second argument of preg_replace * @return Zend_Filter_PregReplace */ public function setReplacement($replacement) { $this->_replacement = $replacement; return $this; } /** * Get currently set replacement value * * @return string */ public function getReplacement() { return $this->_replacement; } /** * Perform regexp replacement as filter * * @param string $value * @return string */ public function filter($value) { if ($this->_matchPattern == null) { require_once 'Zend/Filter/Exception.php'; throw new Zend_Filter_Exception(get_class($this) . ' does not have a valid MatchPattern set.'); } return preg_replace($this->_matchPattern, $this->_replacement, $value); } }