I am an admin of an anime website. And well, I'm trying to refresh some php. We were uploading some manga chapters, which so far are around 438 in total. So I was thinking: "Let me use this opportunity to practice some php."As you know, coding the links to 438 different urls with different names in pure html can be quite a pain. So I decided to make a simple generator to generate the codes for me.Here's what I have so far:
<?php$linkzorz = 1;$html = '<a href="http://myplace.net/mangadir/manga-';$counter = 1;do {echo $html . $linkzorz . '.zip' . '">Chapter ' . $linkzorz . '</a><br />';$counter ++;$linkzorz ++;}While ($counter <= 438);?>
The code is flawless,Reading that, you can see that it will generate 438 lines of the hyperlink code, with variable numbers which increase each time.My problem is that, the chapters are named in the following way: chapter-001, chapter-022, chapter-333.Therefore I assume that I may use the if statement to add '00' in front of $linkzorz if there is one digit, else if add '0' if there's 2 digits, and just leave it as normal if there's three digits.My question is: "How may I tell php the number of digits in a variable? =[" ( I know this may sound basic. )But that is why I can't make the code. :)Any suggestions?Thanks in advance.