PHP - Count number of commas in string
15,306
Solution 1
substr_count($my_string, ",")
If you wish to get all the elements between commas as an array, you can always
$splitted = explode(",", $my_string)
Solution 2
You could use e.g. substr_count(), or explode().
Related videos on Youtube
Author by
John Links
Updated on June 04, 2022Comments
-
John Links almost 2 years
How can I count the number of times a comma appears in a string such as this?
A,B,C,D
It should return "3"