PHP/Smarty 删除字符后的所有内容

PHP/Smarty Remove Everything after character

我想删除下划线后的所有内容,我有这个:

{$result.searchname|escape:"htmlall"|replace:".":" "|strstr:'_':true}

到目前为止效果很好。我现在的问题是

|strstr:'_':true

标题中没有下划线的HTML标题全部不再显示

http://www.smarty.net/docs/en/language.modifier.regex.replace.tpl

{'hello_world'|regex_replace:'/_.*/':''} 将打印 "hello"

此外,我对他们的注释有强烈的感觉,建议您尽可能在将数据分配给 smarty 之前执行字符串处理:

Although Smarty supplies this regex convenience modifier, it is usually better to apply regular expressions in PHP, either via custom functions or modifiers. Regular expressions are considered application code and are not part of presentation logic.