Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $text = "The Milky Way is the galaxy that contains our star system";
- $length = 10;
- //$text = $_GET['text'];
- //$length = $_GET['lineLength'];
- $lines = str_split($text, $length);
- array_walk($lines, function(&$val) {
- $val = str_pad($val, $GLOBALS['length'], ' ', STR_PAD_RIGHT);
- });
- $verticalWords = array();
- for($i = 0; $i < $length ;$i++) {
- $temp = '';
- for($j = 0; $j < count($lines) ;$j++) {
- $temp .= $lines[$j][$i];
- }
- $verticalWords[] = $temp;
- }
- array_walk($verticalWords, function(&$val) {
- $val = str_replace(' ', '', $val);
- $val = str_pad($val, count($GLOBALS['lines']), ' ', STR_PAD_LEFT);
- });
- echo "<table>";
- for($col = 0; $col < count($lines) ;$col++) {
- echo "<tr>";
- for($row = 0; $row < $length ;$row++) {
- echo "<td>" . htmlspecialchars($verticalWords[$row][$col]) . "</td>";
- }
- echo "</tr>";
- }
- echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement