[SOLVED] Better way for str_pad

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

[SOLVED] Better way for str_pad

Post 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:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

<?php
$id_number = 'NUM0234';
$new_number = ++$id_number;
echo $new_number;
?>
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Post by brewmiser »

Do you ever have that feeling that you can't see the forest because of the tree's? :oops:
Post Reply