我有标题(Architectural_Garden_Hardware-Switch Plates& Outlet Covers)
但我只显示破折号( - )之后的字符(Switch Plates& Outlet Covers)\
怎么做?
{foreach from=elements item=birds}
<option value="{$birds}">{$birds}</option>
/foreach}
答案 0 :(得分:0)
您应该使用strpos和substr,如下例所示:
{assign var="var" value=" ( Architectural_Garden_Hardware-Switch Plates & Outlet Covers )"}
{assign var="pos" value=$var|strpos:"-"}
{$var|substr:($pos+1)}
您还可以使用更短的语法:
{assign var="var" value=" ( Architectural_Garden_Hardware-Switch Plates & Outlet Covers )"}
{$var|substr:($var|strpos:"-"+1)}
所以在你的情况下你可以使用:
{foreach from=elements item=birds}
<option value="{$birds|substr:($birds|strpos:"-"+1)}">{$birds|substr:($birds|strpos:"-"+1)}</option>
{/foreach}