如果匹配单词,则删除字符串的其余部分
Remove rest of string if matches word
我想删除匹配的剩余字符串,例如"exampleword" 聪明。
或者删除字符串的最后 100 个字符?
可以在 smarty 中使用 trim 函数或 PHP?
中的某些函数
可以使用substr()
,示例代码:
echo substr("string of 100 characters ore more...", -5); // re...
echo substr("string of 100 characters ore more...", 0, -5); // string of 100 characters ore mo
$smarty = new Smarty;
$smarty->assign('name', substr('george smith', 0, -3));
$smarty->display('index.tpl');
在示例 #1 中查看 here 以查找示例 #2 中的负数开头或长度(取决于您想要 return 的部分),但一定要检查字符串是否实际上大于100 个字符(使用 strlen()
),然后再执行此操作。
我想删除匹配的剩余字符串,例如"exampleword" 聪明。 或者删除字符串的最后 100 个字符? 可以在 smarty 中使用 trim 函数或 PHP?
中的某些函数可以使用substr()
,示例代码:
echo substr("string of 100 characters ore more...", -5); // re...
echo substr("string of 100 characters ore more...", 0, -5); // string of 100 characters ore mo
$smarty = new Smarty;
$smarty->assign('name', substr('george smith', 0, -3));
$smarty->display('index.tpl');
在示例 #1 中查看 here 以查找示例 #2 中的负数开头或长度(取决于您想要 return 的部分),但一定要检查字符串是否实际上大于100 个字符(使用 strlen()
),然后再执行此操作。