HBcms是一个用Pear框架+Smarty模板引擎构架的cms项目,欢迎大家参与制作Smarty模板

regex_replace
正则替换

Parameter Position参数位置 Type类型 Required必需 Default默认 Description
1 string Yes n/a

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

2 string Yes n/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
Smarty手册范例 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]/":" "} 输出结果: Infertility unlikely to be passed on, experts say. Infertility unlikely to be passed on, experts say.
这是一份简单的Smarty手册和Smarty教材,熟练掌握Smarty模板,让您做项目事半功倍