How to count the number of times a comma appears on such a line?
A, B, C, D
He must return "3"
substr_count($my_string, ",")
If you want to get all the elements between commas as an array, you can always $splitted = explode(",", $my_string)
$splitted = explode(",", $my_string)
You can use for example. substr_count () or explode () .