检查字符串是否包含逗号

2022-08-31 00:04:33

检查字符串中是否包含逗号?我有一个刺痛我怎么能检查它,它包含逗号分隔的值与否

example : $search=6,7,8,9,10

答案 1

php 函数返回字符串的位置,如果它不是 false 或 -1,则字符串包含字符。strpos

$searchForValue = ',';
$stringValue = '115,251';

if( strpos($stringValue, $searchForValue) !== false ) {
     echo "Found";
}

答案 2

您可以尝试使用preg_mathstrpos 方法。

$re = '/,/m';
$str = 'Hi...1,2,3,4';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

推荐