Reputation: 327
Check if string contains commas in it? i have a sting how can i check it it contains comma separated values or not
example : $search=6,7,8,9,10
Upvotes: 17
Views: 65316
Reputation: 2587
php function strpos
return position of string if it's not false or -1 then your string contain character.
$searchForValue = ',';
$stringValue = '115,251';
if( strpos($stringValue, $searchForValue) !== false ) {
echo "Found";
}
Upvotes: 58
Reputation: 10037
You can try with preg_math or strpos methods.
$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);
Upvotes: 0