<?php
$str1='1,11,12,15,18';
$textStr = '1';
$arr = explode(',', $str1);
if (in_array($textStr, $arr))
{
echo "true";
}
else
echo "false";
?>
$str1='1,11,12,15,18';
$textStr = '1';
$arr = explode(',', $str1);
if (in_array($textStr, $arr))
{
echo "true";
}
else
echo "false";
?>
$str1='1,11,12,15,18';
$str2='12';
$textStr = '1';/*
实际正则是 '/(^[^0-9,]1,|,1,|,1[^0-9,]$/ 按照给出格式只有3种可能
1开头 2中间 3最后 所以只要匹配3种可能中的一个,就找到了相应的位置
*/
preg_match_all('/^[^0-9,]*'.$textStr.',|,'.$textStr.',|,'.$textStr.'[^0-9,]*$/', $str1, $str1Arr);preg_match_all('/^[^0-9,]*'.$textStr.',|,'.$textStr.',|,'.$textStr.'[^0-9,]*$/', $str2, $str2Arr);print_r($str1Arr);print_r($str2Arr);
?>