PHP BASICS - typecasting dilemma
<p>In the following code, <code>$counter</code> variable is typecast to store integers as per this line <code>$counter=(int)fread($fp, 20);</code> then why <code>strlen($counter)</code> is used. I mean, strlen returns length of a string however <code>$counter</code> now is already an integer variable. Same goes for substr($counter, $i,1). The program gives the desired result, it's just that I do understand as explained above.</p>

<pre><code>

$counter_file = "./count.txt";
$img_dir="./img";
if(!($fp=fopen($counter_file, "r"))) die ("Could not find $counter_file");
$counter=(int)fread($fp, 20);
fclose($fp);

$counter++;

for ($i=0; $i&lt;strlen($counter); $i++){

 $img_src = $img_dir."/".substr($counter, $i,1).".jpg";
 $img_tag_str .="&lt;img src= \"$img_src\" border=\"0\">";

 }
echo "You are visitor no. $img_tag_str.";

$fp=fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
</code></pre>

<p>Regrds,
seni.</p>
