fwrite() insetring spaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

fwrite() insetring spaces

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: fwrite() insetring spaces

Post by VladSun »

Do you show it as an HTML or as a plain text?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: fwrite() insetring spaces

Post 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.
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

Re: fwrite() insetring spaces

Post by carcaix »

I show it like HTML, ok now i will try the <pre></pre> tag, lets see.
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

Re: fwrite() insetring spaces

Post 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.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: fwrite() insetring spaces

Post by DigitalMind »

use pre tags while showing
carcaix
Forum Newbie
Posts: 12
Joined: Sun Aug 29, 2010 9:33 am

Re: fwrite() insetring spaces

Post by carcaix »

Hmm... I have understood to use it as the $string. Ok i will try.

Thanks you.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: fwrite() insetring spaces

Post 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>
Post Reply