-3

I want to print these letters in a HTML-form vertically, now it's in horizontal form.

<html>
<head>
    <meta charset="utf-8" >
    <title></title>     
</head>
<body>
<?php
     $sentence = "What is your first name";
     $letters = str_replace(" ", "", $sentence);
     $letters_array = str_split($letters);

?>
<table cellpadding="3" cellspacing="0" border="1">

<?php
    for($n = 0; $n < strlen($letters); $n++){
        print "<td> " . $letters_array[$n] . " </td>";
        if(($n+1) % 5 == 0){
            print "<tr> ";
        }
    }

?>

</table>
mpromonet
  • 11,326
  • 43
  • 62
  • 91
Salk
  • 1
  • 3

2 Answers2

0

You need to open and close<tr></tr>

Expand print "<td> " . $letters_array[$n] . " </td>";

to

print "<tr><td> " . $letters_array[$n] . " </td></tr>";

And

<td></td>

means table datacell, cells are placed horizontally, until a new row begins.

cli
  • 162
  • 2
  • 10
0

The output is something like this now:


|W |h |a |t |i|


|s |y |o |u |r|

I want it like this:


|W |s |f |n |


|h |y |i |a |


|a |o |r |m |


|t |u |s |e |


|i |r |t |

I can't upload pics, that's why I wrote this like a table.

Salk
  • 1
  • 3
  • ´if(($n+1) % 5 == 0){ print " "; }´ needs to be removed, and you need much more logic if you want it like that. HTML is written left to right, but you need to know what character $n+$number_of_rows is by the time you write second column. – cli Feb 05 '15 at 19:44
  • You need: `print "";` before loop starts, and you need `print "".$letters_array[$n]."".$letters_array[$n+$number_of_rows]."";` inside of the for-loop. Then `if ($n=$number_of_rows) {echo "";}';` inside of loop as well. etcetc. – cli Feb 05 '15 at 19:50