Advertisement
Valleri

Text Gravity

Sep 2nd, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. $text = "The Milky Way is the galaxy that contains our star system";
  3. $length = 10;
  4.  
  5. //$text = $_GET['text'];
  6. //$length = $_GET['lineLength'];
  7. $lines = str_split($text, $length);
  8.  
  9. array_walk($lines, function(&$val) {
  10.     $val = str_pad($val, $GLOBALS['length'], ' ', STR_PAD_RIGHT);
  11. });
  12.  
  13. $verticalWords = array();
  14. for($i = 0; $i < $length ;$i++) {
  15.     $temp = '';
  16.     for($j = 0; $j < count($lines) ;$j++) {
  17.        $temp .= $lines[$j][$i];
  18.     }
  19.     $verticalWords[] = $temp;
  20. }
  21.  
  22. array_walk($verticalWords, function(&$val) {
  23.     $val = str_replace(' ', '', $val);
  24.     $val = str_pad($val, count($GLOBALS['lines']), ' ', STR_PAD_LEFT);
  25. });
  26.  
  27. echo "<table>";
  28. for($col = 0; $col < count($lines) ;$col++) {
  29.     echo "<tr>";
  30.     for($row = 0; $row < $length  ;$row++) {
  31.         echo "<td>" . htmlspecialchars($verticalWords[$row][$col]) . "</td>";
  32.     }
  33.     echo "</tr>";
  34. }
  35. echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement