Re: php: assignment operator
| From: | Anthony Ritter | Date: | Wed, 07 Aug 2002 15:22:50 +0000 |
| Subject: | Re: php: assignment operator | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111505@lists.php.net to get a copy of this message | ||
Exactly. I don't understand. :-0
O.K. The script is a counter.
My question was about the assigment operator
.=
within the following script taken from page 330 of WROX "Beginning PHP 4".
I didn't understand why there was a
.=
as opposed to a
=
and my guess is that by using the .= operator
> > the output would echo ONE placeholder for the IMG SRC from 0
> > through 9 - however when the 10th time the page was loaded it would
still
> > be in the *same* IMG SRC holder and there never be a SECOND IMG SRC
> > holder - to the right - (10 through 99), a third to the right of the
second
> > (100 through 999), etc.
as opposed to using a
= operator
which would only have one SRC placeholder if the page was refreshed the
tenth time around.
The complete script:
........................................
<?
$counter_file="./counter.txt";
$image_dir= "./images";
if(!($fp=fopen($counter_file, "r")))die("Couldn't open the file");
$counter=(int)fread($fp, 20);
fclose($fp);
$counter++;
for($i=0; $i<strlen($counter); $i++)
{
$image_src=$image_dir. "/" .substr($counter, $i, 1) . ".jpg";
$image_tag_src.="<IMG SRC=\"$image_src\" BORDER=\"0\">";
}
echo "You are visitor $image_tag_src";
$fp=fopen($counter_file, "w");
fwrite($fp,$counter);
fclose($fp);
?>
....................................
Thank you.
TR
........................................
Mike Ford:
> Huh? I really don't understand what you're trying to say here, nor how
number of times the page is loaded comes into it at all. I get the
impression that you don't seem to understand what's going on here either --
so, let's take a step back, and ask if you can tell us what you think this
code fragment is doing, and what you want it to do, and then perhaps we can
work out whose misconception is where. Oh, and it would help to know what
values of $counter are involved, too!