如何从字符串中删除 Smarty 中的第一个单词,如下所示:
$variable = "Word Quick brown fox";
然后在输出上使它看起来像这样:
$variable = "Quick brown fox";
有没有办法在没有修饰符的情况下做到这一点?我知道你可以制作自定义修饰符,然后使用$variable|customModifier
并得到你想要的,但我想也许已经有内置的解决方案了?
正如 Tyler 指出的那样,这应该在您的业务逻辑中完成,如下所示:
explode()
在空间上创建单词数组array_shift()
(对应句子中的第一个单词)implode()
这是一个例子:
$words = explode( ' ', $variable);
array_shift( $words);
$variable = implode( ' ', $words);
通过单词之间的空格将原始字符串分解成一个数组,然后切出所选的索引键。然后将数组内爆回字符串。
<?php
$variable = "Word Quick brown fox";
$str = explode(' ', $variable);
$str = array_slice($str, 1);
$str = implode(' ', $str);
echo $str;
?>