Is there a php function that is able to replace when a character appear x time?

example

```
$string="a,b,c,d,e,f,g,h,i,j,k,l";

```

every 3 commas will append "\n\r"

```
a,b,c,
d,e,f,
g,h,i,
j,k,l

```

I have written this.

```
function addBreaks($string,$char,$count) {  
    $ii = 0;
    for ( $i = 0; $i < strlen($string); $i++){  
        if ($string[$i] == $char){
            $ii++;      
            }
        if ($ii == $char){      
            $ii = 0;

            }
        $string = $string[$i]+"\n\r"+$string[$i+1]; 
        }
        return $string;
    }

```