mirror of
https://github.com/jbcr/core.git
synced 2026-03-31 13:22:09 +02:00
Add preg_replace twig filter
This commit is contained in:
@@ -22,6 +22,7 @@ class TextExtension extends AbstractExtension
|
||||
new TwigFilter('safestring', [$this, 'safeString']),
|
||||
new TwigFilter('slug', [$this, 'slug']),
|
||||
new TwigFilter('ucwords', [$this, 'ucwords']),
|
||||
new TwigFilter('preg_replace', [$this, 'pregReplace']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,4 +44,12 @@ class TextExtension extends AbstractExtension
|
||||
|
||||
return ucwords($string, $delimiters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a regular expression search and replace on the given string.
|
||||
*/
|
||||
public function pregReplace(string $str, string $pattern, string $replacement = '', int $limit = -1): string
|
||||
{
|
||||
return preg_replace($pattern, $replacement, $str, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user