Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string contains commas

Tags:

string

php

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
like image 318
Sumit Nair Avatar asked May 11 '16 07:05

Sumit Nair


People also ask

How do you check if there is a comma in a string Java?

Just count the amount of commas in the String and compare it the length of it. Then they are not equal, then there is more than just commas.

How do you check if a string contains a certain character?

Use the String. includes() method to check if a string contains a character, e.g. if (str. includes(char)) {} . The include() method will return true if the string contains the provided character, otherwise false is returned.

How to check if a string contains only numbers and commas?

There are numerous ways to check if a string contains only numbers and comma. We are going to use one of the easiest solutions which involve the usage of the match () method and ternary (?) operator. The match () methods matches a string against a regular expression. If the match is found, it returns an array of matches, otherwise returns null.

Why do we put commas in numbers?

In large numbers, a comma is used to improve the readability. A comma is placed every three decimal places to the left of the decimal point. It is used with numbers that have 4 or more digits. There are numerous ways to check if a string contains only numbers and comma.

How to check if a string contains any special characters?

Now, if there exist any ‘character matches’ with the regular expression then the string contains special characters otherwise it does not contain any special characters. Print the result. Writing code in comment?

How to check if a cell contains a string in Excel?

If cell contains one of many text strings, then return a value Select the output cell, and use the following formula: =IF (OR (ISNUMBER (SEARCH ("string1", cell)), ISNUMBER (SEARCH... For our example, the cell we want to check is A2. We’re looking for either “tshirt” or “hoodie”, and the return ...


1 Answers

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";
}
like image 171
Maninderpreet Singh Avatar answered Sep 24 '22 05:09

Maninderpreet Singh