Sumit Nair
Sumit Nair

Reputation: 327

Check if string contains commas

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

Answers (2)

Maninderpreet Singh
Maninderpreet Singh

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

Arshid KV
Arshid KV

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

Related Questions