| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | # replace
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | A simple search and replace on a variable. This is equivalent to the | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | PHP's [`str_replace()`](https://www.php.net/str_replace) function. | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ## Basic usage
 | 
					
						
							|  |  |  | ```smarty | 
					
						
							|  |  |  | {$myVar|replace:"foo":"bar"} | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ## Parameters
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | | Parameter Position | Type   | Required | Description                                 | | 
					
						
							|  |  |  | |--------------------|--------|----------|---------------------------------------------| | 
					
						
							|  |  |  | | 1                  | string | Yes      | This is the string of text to be replaced.  | | 
					
						
							|  |  |  | | 2                  | string | Yes      | This is the string of text to replace with. | | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ## Examples
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ```php | 
					
						
							|  |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | $smarty->assign('articleTitle', "Child's Stool Great for Use in Garden."); | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | Where template is: | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ```smarty | 
					
						
							|  |  |  | {$articleTitle} | 
					
						
							|  |  |  | {$articleTitle|replace:'Garden':'Vineyard'} | 
					
						
							|  |  |  | {$articleTitle|replace:' ':'   '} | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  |         | 
					
						
							|  |  |  | Will output: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | Child's Stool Great for Use in Garden. | 
					
						
							|  |  |  | Child's Stool Great for Use in Vineyard. | 
					
						
							|  |  |  | Child's   Stool   Great   for   Use   in   Garden. | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 14:42:31 +01:00
										 |  |  | See also [`regex_replace`](language-modifier-regex-replace.md) and | 
					
						
							|  |  |  | [`escape`](language-modifier-escape.md). |