| 148 |
lars |
1 |
replace {#language.modifier.replace}
|
|
|
2 |
=======
|
|
|
3 |
|
|
|
4 |
A simple search and replace on a variable. This is equivalent to the
|
|
|
5 |
PHP\'s [`str_replace()`](&url.php-manual;str_replace) function.
|
|
|
6 |
|
|
|
7 |
Parameter Position Type Required Default Description
|
|
|
8 |
-------------------- -------- ---------- --------- ---------------------------------------------
|
|
|
9 |
1 string Yes *n/a* This is the string of text to be replaced.
|
|
|
10 |
2 string Yes *n/a* This is the string of text to replace with.
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
<?php
|
|
|
14 |
|
|
|
15 |
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
|
|
16 |
|
|
|
17 |
?>
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
Where template is:
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
{$articleTitle}
|
|
|
25 |
{$articleTitle|replace:'Garden':'Vineyard'}
|
|
|
26 |
{$articleTitle|replace:' ':' '}
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
Will output:
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
Child's Stool Great for Use in Garden.
|
|
|
34 |
Child's Stool Great for Use in Vineyard.
|
|
|
35 |
Child's Stool Great for Use in Garden.
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
See also [`regex_replace`](#language.modifier.regex.replace) and
|
|
|
40 |
[`escape`](#language.modifier.escape).
|