ClarkeRubber

UNSW ProgComp: Problem 3 - 2007

Jun 10th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. <?php
  2.  
  3. $input = <<<END
  4. 10 15
  5. Time
  6. flies
  7. like
  8. an
  9. arrow
  10. but
  11. fruit
  12. flies
  13. like
  14. a
  15. banana
  16. Groucho
  17. Marx
  18. END;
  19.  
  20. //number of word, width
  21. $input = explode("\n", $input);
  22. $first_line = explode(" ", array_shift($input));
  23. $width = $first_line[1];
  24. //ignore the word count
  25.  
  26. foreach($input as $key => $value){
  27.     $echo_key = $key+1;
  28.     echo str_pad($value, $width-strlen($echo_key), '.', STR_PAD_RIGHT).$echo_key."\n";
  29. }
Advertisement
Add Comment
Please, Sign In to add comment