|
Posted by Pedro Graca on 10/11/06 12:17
a wrote:
> I just don't know why the counter.txt just contains the last digit and so
> can't accumulate more than 9. furthermore, could anybody tell me in case
> php.net help doesn't return explanations, what else place i can go for to
> check whether I'm using the functions correctly? Thanks a lot
>
> $filename ="counter.txt";
>
> $handle = fopen($filename, 'r');
>
> $content = fread($handle, filesize($filename));
$content is now a string.
> list ($counter) = $content;
But you treat it as an array!
What happens is that PHP takes every single character in $content as
each element of the array.
Try this:
<?php
$content = "42\n";
list($one) = $content;
list($two1, $two2) = $content;
echo '$one is ', $one, "<br>\n";
echo '$two1 is ', $two1, ' and $two2 is ', $two2, "<br>\n";
?>
Anyway, $content already has the value that was in the file. If you need
another variable to hold that value, just do
if (is_numeric($content)) {
$counter = (int)$content;
} else {
$counter = 0; // or some other initialization value (1 ??)
}
<snip>
--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Navigation:
[Reply to this message]
|