regex_replace

パラメータの位置?必須デフォルト概要
1string?Yesn/a置換するための正規表現
2string?Yesn/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.

2005年07月08日(金) 11:03:16 Modified by smarten




スマートフォン版で見る