简体   繁体   中英

PHP/Smarty Remove Everything after character

I want to remove everything after the underline and I have this:

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

which works well so far. My problem is now that by

|strstr:'_':true

all the HTML title who do not have a underscored in title are no longer displayed.

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

{'hello_world'|regex_replace:'/_.*/':''} will print "hello"

Also, I feel quite strongly about their note and would recommend you perform the string processing before the data is assigned to smarty where possible:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM