Page 1 of 1

[SOLVED] Better way for str_pad

Posted: Sun Jun 27, 2004 3:29 pm
by brewmiser
Is there a better way to do the following code snipet?

Code: Select all

$id_number       = "NUM0234";
$only_number   = substr($id_number, 3);
$new_number   = str_pad($only_number+1, 7, "NUM0", left);
Answer = NUM0235 (Basically the code just increases the string by one.)

I am a self taught coder and I am always trying to learn more ways of doing more streamlined and/or efficient code.

Thanks for your help in advance :wink:

Posted: Sun Jun 27, 2004 3:44 pm
by markl999

Code: Select all

<?php
$id_number = 'NUM0234';
$new_number = ++$id_number;
echo $new_number;
?>

Posted: Sun Jun 27, 2004 4:07 pm
by brewmiser
Do you ever have that feeling that you can't see the forest because of the tree's? :oops: