Page hit counter by using digit images for graphical displayWe will try to create graphical or attractive digit counter by using our PHP counter script. The purpose of this script is to display images like below in place of simple displaying the text of numbers.
We will not discuss how the counter should work, how the data is to be read and written to the text file. You can read the counter script file to get the details. We will start from the incremented data or the data, which we are displaying as, counter value and work on it to display image counter.
In that script the variable $contents store the value of the present value of the counter. We will start from there.
Here to display a graphical counter we have to call the digits. We will have graphical digits from 0 to 9 in different styles stored in different directories. To display in particular style we will call the digits of the directory.
To display the number 502 we will call or display the digit 5.gif then 0.gif and then 2.gif. This will make the graphical counter. Same way to display 758 counter value we will call first 7.gif then we will call 5.gif and then we will display 8.gif. We have kept different style of digits in different directories so by changing the directory name we can change the style of the digits.
Now let us find out how to know what digit to display by reading the number. There can be many ways here. One is to use string functions to identify the digits in the number. We will use mathematical functions to do that here. You can develop your own way to do this also. As our number system is of base 10 so dividing a number by 10 and collecting the reminder will give us the right most digit. So if we divide 502 by 10 then we will get 2 as reminder and we can store it in an array. Then the quotient can again be divided by 10 to get the next number( 50/ 10 will give reminder 0 ) and we will do this till we get all the digits. Here is the code to do this.
$cdisp=$contents; // Storing the counter value in another variable