Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串
$str = '11,22,33';
$str = '22,44,55;
$str = '66,22;
我如何使用 preg 匹配,以便通过匹配任何字符串中的 22 将产生输出为 1 即(对于案例 1,它应该匹配“,22”,对于案例 2 是 shd 匹配“22”,对于案例 3,它应该匹配“ ,22")
<?php $str = '11,22,33'; $findme = '22'; $pos = strpos($str, $findme); if ($pos !== false) { //found it } ?>
使用这个正则表达式:
/,?22,?/
使用 php.net
http://php.net/manual/en/function.preg-match.php