phphtmltexthtml-tablestretching

How to let text adapt to a set table width instead of stretching the table?


I thought that this would make a table with a set width, and that text would automatically try to fit in by starting on a new line. However, the table still gets stretched by long lines of text.

<HTML><center><table width="300" border="1"><tr><td>
<?php
If (file_exists("file.txt")){
    Echo nl2br(file_get_contents("file.txt"));
}Else{
    Echo "File not found.";
}
?>
</td></tr></table></center></HTML>

alt text

I think I'm forgetting something absolutely essential here.. 0.o


Solution

  • Change the code to this:

      echo nl2br(wordwrap(file_get_contents("file.txt")));
    

    There is a built in function in PHP called wordwrap for such tasks.