I am trying to iterate with a for loop through 8 digits starting from 0. For example, the first number: 00000000 , and I would like to display the next 5 numbers. So far, I have succeeded. eg:
<?php $start = 00000000; $number = 5; for ($i = $start; $i < $start + $number; $i++) { $url = sprintf("http://test.com/id/%08d", $i); echo $url . "\r\n"; } ?>
Result:
http://test.com/id/00000000 http://test.com/id/00000001 http://test.com/id/00000002 http://test.com/id/00000003 http://test.com/id/00000004
Everything is fine there with this example, but problems begin with this example:
<?php $start = 00050200; $number = 5; for ($i = $start; $i < $start + $number; $i++) { $url = sprintf("http://test.com/id/%08d", $i); echo $url . "\r\n"; } ?>
The for loop creates:
http://test.com/id/00020608 http://test.com/id/00020609 http://test.com/id/00020610 http://test.com/id/00020611 http://test.com/id/00020612
when i expect:
http://test.com/id/00050200 http://test.com/id/00050201 http://test.com/id/00050202 http://test.com/id/00050203 http://test.com/id/00050204
Peter source share