-2

I'm using this code:

$start = substr($string, 0, -6);
$end = substr($string, -6);
for($i = 0; $i < 500; $i++) {
    if($end > 500) {
        echo $start.$end--."<br />";
    } else {
        echo $start.$end++."<br />";
    }
}

Where $string will something like RXV123456 always last 6 characters will be a number.

If $string is RXV123456, the output will be someting like:

RXV123456
RXV123455
RXV123454
...

But, if $string will be something like RXV012345, I get this output:

RXV12345
RXV12344
RXV12343

Also if $string will be RXV001234 or RXV000123, same thing, that zeros will be omitted.

Any ideas how to keep the zeros if $end will start with one ore more zeros?

  • Make sure it is a string. If you have to work with numbers then you will need to convert it. – John Conde May 10 '13 at 18:28
  • Always remember to read the FAQ - especially the part where it tells you to look for where it's already been answered. http://stackoverflow.com/questions/1699958/formatting-a-number-with-leading-zeros-in-php – Wolfman Joe May 10 '13 at 18:29
  • i searched, but didn't found that topic –  May 10 '13 at 18:30
  • I was searching for preceeding zeros, not leading zeros, my english isn't that good –  May 10 '13 at 18:41
  • @AdrianG leading zeroes and preceding zeroes in this case mean the same thing. zeroes that come before an integer. – Jonathan Kuhn May 10 '13 at 18:45

1 Answers1

1

Any programming language will truncate zeros on the left side of an integer. If you want them to display, you can use a function like str_pad to add them when concatenating with the other string.

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43