Download the PHP package emandiev/regex-replace-twig-filter without Composer
On this page you can find all versions of the php package emandiev/regex-replace-twig-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emandiev/regex-replace-twig-filter
More information about emandiev/regex-replace-twig-filter
Files in emandiev/regex-replace-twig-filter
Package regex-replace-twig-filter
Short Description Adds PHP's preg_replace function as a Twig filter.
License MIT
Informations about the package regex-replace-twig-filter
Regex Replace Twig Filter plugin for Craft CMS 3.x/4.x
Adds PHP's preg_replace function as a Twig filter.
Requirements
This plugin requires Craft CMS 3.x or 4.x
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
-
Then tell Composer to load the plugin:
- In the Control Panel, go to Settings → Plugins and click the “Install” button for Regex Replace Twig Filter.
Usage
Any backslashes in the regular expression must to be double-escaped to work properly.
How is this different from Craft's replace filter?
In short, the preg_replace filter offers a more direct call to PHP's function.
Craft's filter allows for both normal string and regex replacements but slightly limits the regex replacement functionality.
Example 1
preg_replace allows you to use any delimiter, while replace works only with forward slashes .
Example 2
The replace filter performs when an array is passed and always ignores the parameter.
preg_replace binds all it's parameters to PHP's function.
This allows you to pass arrays for the and parameters, and an integer for the parameter.
Credits
Brought to you by Danail Emandiev