检查字符串是否包含PHP中的特定单词?

时间:2017-06-19 15:11:59

标签: php

我有这个字符串:v531123000 如果它包含字符串v531,我想要测试。

我是strpos做到的,但它不起作用:

$pn = $article->getPartNumber();
if (strpos($pn, 'v531') !== false) {
                $lt=30;
            }

我应该搜索另一个不是strpos的功能吗?

1 个答案:

答案 0 :(得分:0)

if (0 === strpos('v531123000', 'v531')) {
   //The String starts 'v531'
}