Do this little trick:
$hello = ",,,3,4,,,5,6,,7,8,";
$hello = implode(",",array_filter(explode(',',$hello)));
If your string is more complicated (i.e. it's a CSV which may potentially have fields wrapped in " " to escape commas you can do this:
$hello = ",,,3,4,,,5,6,,\"I,have,commas\",,7,8,";
$fields = array_filter(str_getcsv($hello));
$hello = str_putcsv($fields);
Where str_putcsv is defined in https://gist.github.com/johanmeiring/2894568 as
if (!function_exists('str_putcsv')) {
function str_putcsv($input, $delimiter = ',', $enclosure = '"') {
$fp = fopen('php://temp', 'r+b');
fputcsv($fp, $input, $delimiter, $enclosure);
rewind($fp);
$data = rtrim(stream_get_contents($fp), "\n");
fclose($fp);
return $data;
}
}