You devide the minutes and seconds by 100, but well, you shouldn't:
$d = $deg + ((($min/60) + ($sec/3600))/100);
should be:
$d = $deg + (($min/60) + ($sec/3600));
one minute is 1/60 degree and a second is 1/60 minute.
for a more thorough answer, see here: PHP extract GPS EXIF data