This one’s on the house
| Compatibility: | EE1, EE2 |
|---|---|
| Latest release: | 2.0.3 (released 2012-02-15) |
| Licensing: | CC Attribution-Share Alike 3.0 |
Compatibility
The download contains both the EE1 and EE2 version. Note: the EE1 compatible
version uses the tag {exp:replace}.
Installation
ExpressionEngine 2
- Download and unzip Low Replace
- Copy the
ee2/low_replacefolder to your/system/expressionengine/third_party/directory - All set!
ExpressionEngine 1
- Download and unzip Low Replace
- Copy the
ee1/pi.replace.phpfile to your/system/plugins/directory - All set!
Template tags
| Parameter | Description |
|---|---|
casesensitive |
When set to no, the plugin performs a case insensitive find and replace. |
find |
Text or pattern to replace. Required. |
flags |
Additional pattern modifiers, use in combination with regex="yes". Use the casesensitive parameter instead of the i flag. EE2 only. |
multiple |
When set to yes, you can use a | to define multiple values in both the find and replace parameters. |
regex |
When set to yes, you can use a regular expression in the find parameter, and use callbacks in the replace parameter. |
replace |
Replacement text. Defaults to an empty string. |
Usage notes
ExpressionEngine strips the white space from the beginning and the end of each parameter. Because of this, if you want to
replace something with a space, use the string SPACE instead. You can also use the string QUOTE
for a double quote, PIPE for a | and NEWLINE to match new lines.
When using regex="yes", it is recommended that you set your Debug Preference (Admin > System Preferences
> Output and Debugging Preferences) to 1, so Super Admins can make sure their regular expressions aren’t generating
server errors.
Examples
Replace A with B:
{exp:low_replace find="you" replace="we"}
text you want processed
{/exp:low_replace}
Result: text we want processed
Replace A with a space:
{exp:low_replace find="o" replace="SPACE"}
text you want processed
{/exp:low_replace}
Result: text y u want pr cessed
Replace a space with nothing:
{exp:low_replace find="SPACE"}
text you want processed
{/exp:low_replace}
Result: textyouwantprocessed
Replace a new line with a space:
{exp:low_replace find="NEWLINE" replace="SPACE"}
text
you
want
processed
{/exp:low_replace}
Result: text you want processed
Replace A, B and C with D:
{exp:low_replace find="a|e|i|o|u" replace="X" multiple="yes"}
text you want processed
{/exp:low_replace}
Result: tXxt yXX wXnt prXcXssXd
Replace A, B and C with X, Y and Z:
{exp:low_replace find="text|you|want" replace="words|we|have" multiple="yes"}
text you want processed
{/exp:low_replace}
Result: words we have processed
Regular Expression find and replace:
{exp:low_replace find="\w+" replace="*" regex="yes"}
text you want processed
{/exp:low_replace}
Result: * * * *
Regular Expression find and replace with backreference:
{exp:low_replace find="<a[^>]*href=QUOTE(.+)QUOTE[^>]*>(.*)<\/a>" replace="$2 ($1)" regex="yes"}
<a href="http://www.foo.com/">text</a> you want <a href="http://www.bar.com/">processed</a>
{/exp:low_replace}
Result: text (http://www.foo.com/) you want processed (http://www.bar.com/)