diff --git a/docs/mods/ematch.md b/docs/mods/ematch.md new file mode 100644 index 0000000..a2680d6 --- /dev/null +++ b/docs/mods/ematch.md @@ -0,0 +1,18 @@ +Modifier ematch +============== + +Perform a regular expression match. +[Read more](http://www.php.net/manual/en/reference.pcre.pattern.syntax.php) about regular expression. + + +``` +{$string|ematch:$pattern} +``` + +Searches `$string` for a match to the regular expression given in `$pattern`. + +```smarty +{if $color|ematch:'/^gr[ae]y$/i'} + some form of gray ... +{/if} +``` \ No newline at end of file diff --git a/docs/mods/ereplace.md b/docs/mods/ereplace.md new file mode 100644 index 0000000..cb382dc --- /dev/null +++ b/docs/mods/ereplace.md @@ -0,0 +1,23 @@ +Modifier ereplace +================= + +Perform a regular expression search and replace. +[Read more](http://www.php.net/manual/en/reference.pcre.pattern.syntax.php) about regular expression. + +``` +{$string|replace:$pattern:$replacement} +``` + +Searches `$string` for matches to `$pattern` and replaces them with `$replacement`. + +`$replacement` may contain references of the form `\n`, `$n` or `${n}`, with the latter form being the preferred one. +Every such reference will be replaced by the text captured by the n'th parenthesized pattern. n can be from 0 to 99, +and `\0` or `$0` refers to the text matched by the whole pattern. +Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern. +To use backslash in replacement, it must be doubled. + +```smarty +{var $string = 'April 15, 2014'} + +{$string|ereplace:'/(\w+) (\d+), (\d+)/i':'${1}1, $3'} {* April1, 2014 *} +``` \ No newline at end of file diff --git a/docs/mods/esplit.md b/docs/mods/esplit.md new file mode 100644 index 0000000..53636a8 --- /dev/null +++ b/docs/mods/esplit.md @@ -0,0 +1,19 @@ +Modifier esplit +=============== + +Split string by a regular expression. +[Read more](http://www.php.net/manual/en/reference.pcre.pattern.syntax.php) about regular expression. + +``` +{$string|esplit:$pattern = '/,\s*/'} +``` + +My default modifier split string by comma with spaces. + +```smarty +{var $fruits1 = "banana, apple, pear"|esplit} +$fruits1 is array ["banana", "apple", "pear"] + +{var $fruits2 = "banana; apple; pear"|esplit:'/;\s/'} is ["banana", "apple", "pear"] +$fruits2 is array ["banana", "apple", "pear"] too +``` \ No newline at end of file diff --git a/docs/mods/join.md b/docs/mods/join.md new file mode 100644 index 0000000..f384cfc --- /dev/null +++ b/docs/mods/join.md @@ -0,0 +1,16 @@ +Modifier split +============== + +Join array elements with a string. + +``` +{$string|join:$delimiter = ","} +``` + +Returns an array of strings, each of which is a substring of `$string` formed by splitting it on boundaries formed by the string `$delimiter`. + +```smarty +{var $fruits1 = ["banana", "apple", "pear"]} +{$fruits1|join} output banana, apple, pear +{$fruits1|join:" is not "} output banana is not apple is not pear +``` \ No newline at end of file diff --git a/docs/mods/match.md b/docs/mods/match.md new file mode 100644 index 0000000..e5d9448 --- /dev/null +++ b/docs/mods/match.md @@ -0,0 +1,24 @@ +Modifier match +============== + +Match string against a pattern. +The average user may be used to shell patterns or at least in their simplest form to `?` and `*` wildcards so using `match` +instead of `ematch` for frontend search expression input may be way more convenient for non-programming users. + +``` +{$string|match:$pattern} +``` + +Special pattern symbols: + +* `?` — match one or zero unknown characters. `?at` matches `Cat`, `cat`, `Bat` or `bat`, `but` not `at`. +* `*` — match any number of unknown characters. `Law*` matches `Law`, `Laws`, or `Lawyer`. +* `[characters]` — Match a character as part of a group of characters. `[CB]at` matches `Cat` or `Bat` but not `cat`, `rat` or `bat`. +* `\` - Escape character. `Law\*` will only match `Law*` + + +```smarty +{if $color|match:"*gr[ae]y"} + some form of gray ... +{/if} +``` \ No newline at end of file diff --git a/docs/mods/replace.md b/docs/mods/replace.md new file mode 100644 index 0000000..099bfd0 --- /dev/null +++ b/docs/mods/replace.md @@ -0,0 +1,14 @@ +Modifier replace +================ + +Replace all occurrences of the search string with the replacement string + +``` +{$string|replace:$search:$replace} +``` + +This modifier returns a string with all occurrences of `$search` in subject replaced with the given `$replace` value. + +```smarty +{$fruits|replace:"pear":"orange"} +``` \ No newline at end of file diff --git a/docs/mods/split.md b/docs/mods/split.md new file mode 100644 index 0000000..5f4b837 --- /dev/null +++ b/docs/mods/split.md @@ -0,0 +1,18 @@ +Modifier split +============== + +Split a string by string + +``` +{$string|split:$delimiter = ","} +``` + +Returns an array of strings, each of which is a substring of `$string` formed by splitting it on boundaries formed by the string `$delimiter`. + +```smarty +{var $fruits1 = "banana,apple,pear"|split} +$fruits1 is array ["banana", "apple", "pear"] + +{var $fruits2 = "banana,apple,pear"|split:',apple,'} +$fruits2 is array ["banana", "pear"] +``` \ No newline at end of file