I have a large string of text (variable) and i need to loop through it and count how many commas are in each group of the string. The string is in a variable ($string) and each group is surrounded in parenthesis (data, data, data).
so if
$string = (data, data, data), (data, data, data), (data, data), (data, data, data);
and
$x = 3;
I need to loop through this string and find all the groups that don't have $x items and add a blank one at the end to those without $x.
so the item: (data, data)
would need to be: (data, data, '')
I understand all i'd need to do is do a
str_replace(")",", '')", $string);
However, how do I ungroup those to see how many are in each row?
If it must be exploded into an array, that's fine, but I need it back in the string format to import into MySQL.
Thanks for the help.
so if
$string = (data, data, data), (data, data, data), (data, data), (data, data, data);
and
$x = 3;
I need to loop through this string and find all the groups that don't have $x items and add a blank one at the end to those without $x.
so the item: (data, data)
would need to be: (data, data, '')
I understand all i'd need to do is do a
str_replace(")",", '')", $string);
However, how do I ungroup those to see how many are in each row?
If it must be exploded into an array, that's fine, but I need it back in the string format to import into MySQL.
Thanks for the help.