regex_replace
パラメータの位置 | 型? | 必須 | デフォルト | 概要 |
1 | string? | Yes | n/a | 置換するための正規表現 |
2 | string? | Yes | n/a | この文字列に置換する |
変数に対して正規表現による置換を行います。 正規表現にはphpマニュアルのpreg_replace()の構文を使用して下さい。
例 5-14. regex_replace
<?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 and new line with a space *}
{$articleTitle}
{$articleTitle|regex_replace:"/[\r\t\n]/":" "}
出力 :
Infertility unlikely to
be passed on, experts say.
Infertility unlikely to be passed on, experts say.