字符串的 Smarty 通配符选择器

Smarty wildcard selector for string

快速简单,我有一个完全适用于 Smarty 的应用程序;基本上我有 {if} 语句来确定用户当前正在查看的 URI,因此我可以决定提供什么,它看起来像:

    $GLOBALS.user_page_uri == '/private-messages/contacts/'

这会打开所有联系人,当您单击某些联系人时,您会打开 /private-messages/contacts/ID 所以我需要某种通配符,它​​会出现在上面代码的末尾,所以它只查找“/private-messages/contacts/”并忽略之后的所有内容,我尝试了“*”和“%”但无济于事。

经过几个小时的摸索(我不是 PHP/smarty 专家)我设法找到了解决方案,而不是 $string = 'something' 我使用 preg_match()

所以我通过给它工作:

preg_match("/\/private-messages\/contacts.*/s", $GLOBALS.user_page_uri);

希望有人觉得这有帮助,我知道它救了我很多。