problem with file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Davide

    problem with file

    Hi all.

    I've got a textual file with some words inside:

    file = foo.txt

    foo1 foo2
    foo3 foo4
    foo5 foo6

    I would like to print this text on a the web.
    I tried to use the file function:

    $file = "/var/www/backup/foo.txt";
    $content = file_get_conten ts($file);
    echo "$content";

    but I get
    foo1 foo2 foo3 foo4 foo5 foo6

    how can I get the output as the original file?
    Really thanx

  • Erwin Moller

    #2
    Re: problem with file

    Davide wrote:
    Hi all.
    >
    I've got a textual file with some words inside:
    >
    file = foo.txt
    >
    foo1 foo2
    foo3 foo4
    foo5 foo6
    >
    I would like to print this text on a the web.
    I tried to use the file function:
    >
    $file = "/var/www/backup/foo.txt";
    $content = file_get_conten ts($file);
    echo "$content";
    >
    but I get
    foo1 foo2 foo3 foo4 foo5 foo6
    >
    how can I get the output as the original file?
    Really thanx
    That IS the original file. Really. :-)

    Browsers do not display the newline character \n.
    They ignore it.
    If you need a newline in HTML use <br>.

    So you have to replace your newlines with <brbefore echoing it.

    eg:

    echo nl2br($content) ;
    or
    echo str_replace("\n ","<br>",$conte nt);

    Regards,
    Erwin Moller

    Comment

    Working...