Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个刺痛:
$string = "this string is a lorem ipsum string"
在第 4 个单词之后,我想添加一个关键字,例如:
$keyword = "newword"
现在结果应该是这样的
$newstring = "this string is a newword lorem ipsum string"
我如何在 tpl 文件中使用 smarty 处理这个问题?
好久没用Smarty了,不过你可以在PHP里面做这个,注入到模板中或者在模板中使用PHP:
{php} $array = explode(' ', $string); $result = implode(' ', array_merge(array_splice($array, 0, 4), [$keyword], $array)); {/php}