I have a string of that displays like this:
1235, 3, 1343, 5, 1234, 1
I need to replace every second comma with a semicolon
i.e.
try this:
$s = '1235, 3, 1343, 5, 1234, 1'; $is_second = false; for ($i = 0; $i < strlen($s); $i++) { if ($is_second && $s[$i] == ',') { $s[$i] = ';'; } elseif ($s[$i] == ',') { $is_second = true; } } echo $s;