Page 1 of 1

fwrite() insetring spaces

Posted: Fri Oct 01, 2010 1:28 pm
by carcaix
fwrite($handle, "start".$string."end");

I have been trying to insert a great number of spaces in the $string statement using chr(32) and " " and ' '. But when I open the text file from my website with the fgets() function it doesn't show more than one space.

Does anyone have a thought?

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 2:23 pm
by VladSun
Do you show it as an HTML or as a plain text?

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 2:49 pm
by DigitalMind
VladSun wrote:Do you show it as an HTML or as a plain text?
Absolutely correct question. Use something like echo '<pre>' . $result . '</pre>' if you want to show all spaces.

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 3:01 pm
by carcaix
I show it like HTML, ok now i will try the <pre></pre> tag, lets see.

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 3:37 pm
by carcaix
$html = "<pre> </pre>";

fwrite($handle, "start".$html."end");

It doesn't work fine. Instead of leaving my number of spaces it shows some new lines.

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 3:46 pm
by DigitalMind
use pre tags while showing

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 4:13 pm
by carcaix
Hmm... I have understood to use it as the $string. Ok i will try.

Thanks you.

Re: fwrite() insetring spaces

Posted: Fri Oct 01, 2010 5:43 pm
by DigitalMind
Browsers always truncate spaces in HTML pages. If you write 100 spaces in your text, the browser will remove 99 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity or use: <pre>some text that will be shown as is</pre>