php 在 TWIG 中查找字符串中的子字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13007288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:39:07  来源:igfitidea点击:

Find substring in the string in TWIG

phptwigsubstringcomparison-operators

提问by user1440167

I want to find substring of the string or check if there is no such substring using Twig. On the words, I need analogue of 'strstr' or 'strpos' in php. I googled and searched this issue in stackoverflow but nothing found. Does someone know how to solve this problem?

我想找到字符串的子字符串或使用 Twig 检查是否没有这样的子字符串。在单词上,我需要在 php 中类似于“strstr”或“strpos”。我在stackoverflow中用谷歌搜索并搜索了这个问题,但没有找到。有人知道如何解决这个问题吗?

回答by HamZa

Just searched for the docs, and found this:

刚刚搜索了文档,发现了这个

Containment Operator: The inoperator performs containment test. It returns true if the left operand is contained in the right:

收容操作员:in操作员执行收容测试。如果左侧操作数包含在右侧,则返回 true:

{# returns true #}

{{ 1 in [1, 2, 3] }}

{{ 'cd' in 'abcde' }}