Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- 4
- 0509
- 1685
- 2933
- 2259
- END;
- $input = explode("\n", $input);
- array_shift($input); //scrap the first line
- foreach($input as $line){
- $line2 = str_split($line);
- $hour = $line2[0].$line2[1];
- $minute = $line2[2].$line2[3];
- $break = false;
- if($minute > 59 || $hour > 23){
- echo str_pad($line, 7)."Invalid time\n";
- $break = true;
- }
- if($hour > 11){
- $append = ' PM';
- }else{
- $append = ' AM';
- }
- if($hour > 12){
- $hour -= 12;
- }
- if($break == false){
- echo str_pad($line, 7).str_pad(intval($hour), 2, ' ', STR_PAD_LEFT).':'.$minute.$append."\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment