检查字符串与PHP/Smarty中的正则表达式匹配
问题描述:
我想检查一个if查询中是否在字符串中出现特定的字符串(WBT)并对其作出响应。我知道可以在Smarty模板中使用正则表达式,但是不清楚documentation的建议。检查字符串与PHP/Smarty中的正则表达式匹配
这里就是我需要的正则表达式来检查代码,如果该字符串WBT在它发生:
<div class="card-content" style="text-align: center;">
[{if $woche.lehrskript}] // Check if "WBT" occurs in the string lehrskript
<strong>WBT</string>
[{else}]
<strong>[{$woche.lehrskript.name}]</strong>
[{/if}]
</div>
有人能帮助我吗?
答
我已经解决了这样的说法:
[{if strpos($woche.lehrskript.name, 'WBT') != false}]
我还没有使用Smarty的,但你不能只是使用PHP的'strpos'? – chris85
为什么不直接在smarty中使用PHP? – hungrykoala
@hungrykoala .how?真的没有聪明的解决方案吗?我在复杂的代码中工作在一个非常旧的环境中,我真的不知道我还能在哪里知道这些东西。 – Codehan25