在smarty中使用正则替换

将手机号倒数4/5位替换为星号,php的测试用例是这样

<?php

$string = “138265895493”;
$pattern = “/(1d{1,5})dd(d{3,4})/”;
$replacement = “$1**$2″;
print preg_replace($pattern, $replacement, $string);

?>

在smarty中是用regex_replace函数,它参数的写法和php里的preg_replace一样的,可以这样写

<{$sellLogListData.name|regex_replace:”/(1d{1,5})dd(d{3,4})/”:”$1**$2″}>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据