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"
substr_count() is the most appropriate technique. There is no compelling reason to use explode(), then count(), then subtract 1, then cast the number to a string.