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

replace
替换

Parameter Position参数位置 Type参数类型 Required必需 Default默认 Description
1 string Yes n/a This is the string of text to be replaced.
将被替换的文本字串
2 string Yes n/a This is the string of text to replace with.
用来替换的文本字串

A simple search and replace on a variable.
简单的搜索和替换字符串

Example 5-16. replace
Smarty手册范例 5-16.替换

index.php:

$smarty = new Smarty;
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
$smarty->display('index.tpl');

index.tpl:

{$articleTitle}
{$articleTitle|replace:"Garden":"Vineyard"}
{$articleTitle|replace:" ":" "}

输出结果:

Child's Stool Great for Use in Garden.
Child's Stool Great for Use in Vineyard.
Child's Stool Great for Use in Garden.
这是一份简单的Smarty手册和Smarty教材,熟练掌握Smarty模板,让您做项目事半功倍