Check if string contains commas

Check if string contains commas? I have a sting how I can verify that it contains values ​​separated by commas or not.

example : $search=6,7,8,9,10 
+7
source share
2 answers

The php strpos function returns the position of the string; if it is not false or -1, then your string contains a character.

 $searchString = ','; if( strpos($search, $searchString) !== false ) { echo "Found"; } 
+22
source

You can try using the 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); 
0
source

All Articles