regex_replace

PHP Smarty

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

regex_replace 正则替换

Parameter Position参数位置 Type类型 Required必需 Default默认 Description
1 string Yes n/a
2 string Yes n/a This is the string of text to replace with.
用来替换的文本字串
index.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 & new line with a space *}
{* 使用空格替换每个回车,tab,和换行符 *} {$articleTitle} {$articleTitle|regex_replace:"/[\r\t\n]/":" "} OUTPUT: Infertility unlikely to be passed on, experts say. Infertility unlikely to be passed on, experts say.

Prev 来源:PHP中文社区 Home Next
nl2br[替换\n为</br> Up replace[替换]