You are here: Re: problem with file « PHP Programming Language « IT news, forums, messages
Re: problem with file

Posted by Erwin Moller on 03/23/07 16:54

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_contents($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 <br> before echoing it.

eg:

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

Regards,
Erwin Moller

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация