new \Twig_Filter_Method($this, 'highlight'), ); } public function highlight($sentence, $expr) { $expr = explode(' ', $expr); foreach ($expr as $word) { $sentence = preg_replace('/(' . $word . ')/i', '\1', $sentence); } return $sentence; } public function getName() { return 'highlight_extension'; } }