Problem with script counter.php

OK, as it’s getting frustrating, I created some images and ran the original code on my WAMP server here. Out of the box, it works. I don’t quite understand why, but it does. For example, I don’t get why the preg_split line returns this, but then I don’t understand regular expressions to start with.

array (size=7)  { this is $chars[] }
  0 => string '' (length=0)
  1 => string '0' (length=1)
  2 => string '0' (length=1)
  3 => string '0' (length=1)
  4 => string '0' (length=1)
  5 => string '1' (length=1)
  6 => string '' (length=0)

string '00001' (length=5)  {  this is $counterVal }

when I var_dump($chars) followed by $counterVal. Hence the offsets for the array in the original code are correct, starting at 1 and going to 5, not base zero as I said . The echo before imagpng also doesn’t seem to cause any trouble - it works exactly the same whether I leave it in or remove it - I assume imagepng() outputs the image contents, then php follows it with true or false, which is ignored for some reason by the browser.