php端:
$id = 2;
$subject = '1,2,3,4,5,12';
$pattern = '/(^|,)'.$id.'(,|$)/';
if(preg_match($pattern, $subject)){
echo $id;
}else{
echo 'error';
}
mysql端:
从info表ids字段中查询包含2的记录 select * from info where ids regexp '(^|,)2(,|$)';