This would exactly output what you need. Its not that beautiful, u might find a better solution with google, but that just came into my mind:
<?php
$output = "Program: First 0 0 0 0 0 0 0 Program: Second 0 0 0 0 0 Program: Third 0 0 0 0 0 0 0 0";
$output = explode("Program:", $output);
array_splice($output, 0,1 );
$endString = '';
foreach($output as $elem) {
$count = substr_count($elem, "0");
$elemWithoutZero = str_replace('0', '', $elem);
$endString = $endString . 'Program: ' . $elemWithoutZero . $count . ' ';
}
var_dump($endString);
?>
Output:
string(74) "Program: First 7 Program: Second 5 Program: Third 8"
Anyways if you get that kind of data, you might find a better solution at the place where you create that data.