regex_replace
正则替换

Parameter PositionTypeRequiredDefaultDescription
1stringYesn/a

This is the regular expression to be replaced.
替换正则表达式.

2 stringYesn/a This 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.

寻找和替换正则表达式 .
可以从Php手册查找和使用 preg_replace()的语法.

Example 5-15. regex_replace
例 5-15.正则替换

index.php:



$smarty = new Smarty;

$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");

$smarty->display('index.tpl');



index.tpl:



{* replace each carriage return, tab & new line with a space *}
{* 使用空格替换每个回车,tab,和换行符 *} {$articleTitle} {$articleTitle|regex_replace:"/[\r\t\n]/":" "} OUTPUT: Infertility unlikely to be passed on, experts say. Infertility unlikely to be passed on, experts say.