views:

14

answers:

3

Hi,

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

Thanks in advance!

A: 

Try do it by CSS:

word-wrap:break-word 

Also change your width= to style="width: 300px"

killer_PL
+1  A: 

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.

shamittomar
Thank you, I left out width="300" and use the 2nd parameter of wordwrap now to set the length.
Chris
+1  A: 

The text needs to have spaces in order for it to fit in that width. If you have one extremly long word, it will be displayed entirely on one line. You could use the php function wordwrap, which allows you to set the width of the line to a certain number of characters (http://php.net/wordwrap)

A. M.
Thank you for your response :-), using character limit now, not a length in pixels.
Chris