substr help

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
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

substr help

Post by slash85 »

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi quick question:

When doing the following substr then incrementing by one:

Code: Select all

$GetMemberURN = "URN000001";

$URN = substr($GetMemberURN, 0, 3);

$Number =  substr($GetMemberURN, 0, 6) +1;  

$MemberURN = $URN . $Number;

echo $MemberURN;
returns URN2 how can i get it to keep the zero's eg: URN000002


Thanks in advance,
Slash.


hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Post by slash85 »

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/b]


Sorry made a mistake:

Revised:

php:

Code: Select all

$GetMemberURN = "URN000001"; 

$URN = substr($GetMemberURN, 0, 3); 

$Number =  substr($GetMemberURN, 3, 6) +1;  

$MemberURN = $URN . $Number; 

echo $MemberURN;

hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/b]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

slash85
Forum Newbie
Posts: 18
Joined: Fri Feb 03, 2006 12:02 pm

Post by slash85 »

Thanks for the help i went with str_pad(). Worked a treat!
Post Reply