在TWIG中找到字符串中的子字符串 [英] Find substring in the string in TWIG

查看:255
本文介绍了在TWIG中找到字符串中的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Twig查找字符串的子字符串或检查是否没有这样的子字符串.在单词上,我需要在PHP中使用"strstr"或"strpos"的类似物. 我用谷歌搜索并在stackoverflow中搜索了此问题,但未找到任何内容.有人知道如何解决这个问题吗?

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?

推荐答案

只需搜索 docs ,并找到了:

遏制运营商: in 运算符执行遏制性测试. 如果左侧的操作数包含在右侧,则返回true:

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

{# returns true #}

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

{{ 'cd' in 'abcde' }}

这篇关于在TWIG中找到字符串中的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆