The third problem was to simply add up all the digits in the input.
<?
$sum = 0;
while ($line = fgets(STDIN)) {
$matches = array();
preg_match_all("([0-9])", $line, $matches);
$sum += array_sum($matches[0]);
}
echo "$sum\n";