replace

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Chapter 5. Variable Modifiers[变量调节器] Next

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.
用来替换的文本字串
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:" ":" "}

OUTPUT:

Child's Stool Great for Use in Garden.
Child's Stool Great for Use in Vineyard.
Child's Stool Great for Use in Garden.

Prev 来源:PHP中文社区 Home Next
regex_replace[正则替换] Up spacify[插空]