regex_replace

Parameter PositionTypeRequiredDefaultDescription
1stringYesn/aThis is the regular expression to be replaced.
2stringYesn/aThis is the string of text to replace with.

A regular expression search and replace on a variable. Use the syntax for preg_replace() from the PHP manual.

Example 5-14. regex_replace

<?php

$smarty
= new Smarty;
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
$smarty->display('index.tpl');

?>

Where index.tpl is:

{* replace each carriage return, tab and new line with a space *}

{$articleTitle}
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}

This should output:

Infertility unlikely to
be passed on, experts say.
Infertility unlikely to be passed on, experts say.