我有一个刺痛:
$string = "this string is a lorem ipsum string"
在第四个单词后我想添加一个关键字,如:
$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}