Re: php: assignment operator
| From: | Tim Fountain | Date: | Wed, 07 Aug 2002 15:43:05 +0000 |
| Subject: | Re: php: assignment operator | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-111524@lists.php.net to get a copy of this message | ||
On Wednesday, August 7, 2002, Anthony Ritter wrote:
[Not sure what .= does]
> 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);
?>>
.= means add to the value of. So in this case, there's an image file
for each number - 0-9, so if your counter value is 24, you'll need two
images - a two and a four. Similarly, if your counter value was 123,
you'd want three images - a one, a two and a three.
The for loop in the code above loops round once for each digit in
$counter (strlen($counter)), and _adds_ the HTML for the image tag to
the current value of $image_tag_src.
I hope that makes things a little clearer (and that I've understood
your problem correctly!)
--
Tim Fountain (tim@tfountain.co.uk)
http://www.tfountain.co.uk/