How to increment a number and keep as a string?

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
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

How to increment a number and keep as a string?

Post by Deseree »

Input =

$setup_username1 = test0001;

Code: Select all

$setup_username_test = explode("test",$setup_username1);
	
	$setup_number = $setup_username_test[1];
	
	$setup_number = strval(intval($setup_number)+1);
It STILL always shows u as test1 and I need it to show up as all four.

How can I do this please? I just spent an hour and a half trying many things gettting nowhere. strval() did not work.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r "$a = 'test000001'; echo $a 1;"
1
[feyd@home]>php -r "$a = 'test000001'; echo ++$a;"
test000002
Interesting to say the least. :)
Post Reply