php – 什么是python相当于strpos($elem,“text”)!== false)

前端之家收集整理的这篇文章主要介绍了php – 什么是python相当于strpos($elem,“text”)!== false)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
什么是 python相当于:
if (strpos($elem,"text") !== false) {
    // do_something;  
}
未找到时返回-1:
pos = haystack.find(needle)
pos = haystack.find(needle,offset)

当找不到时会引发ValueError:

pos = haystack.index(needle)
pos = haystack.index(needle,offset)

要简单地测试一个子串是否在字符串中,请使用:

needle in haystack

这相当于以下PHP

strpos(haystack,needle) !== FALSE

http://www.php2python.com/wiki/function.strpos/

原文链接:https://www.f2er.com/php/131719.html

猜你在找的PHP相关文章