Require PHP Code:Generate [01-99]

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
iqueen
Forum Newbie
Posts: 8
Joined: Fri Jun 17, 2005 2:46 am

Require PHP Code:Generate [01-99]

Post by iqueen »

Require a php function that can generate a string array by input string.
eg:
input:abc[01-99]
return:abc01,abc02,abc03... abc99;
input:abc[1-99]
return:abc1,abc2,abc3...abc10...abc99
---
Any help is thankful.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

don't double post as you will get in trouble from the mods. :(
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

phpScott wrote:don't double post as you will get in trouble from the mods. :(
That's right. Here's the hammer of doom

Image

or, if you prefer, the sword of damocles

Image

I had to delete your double-post, which I don't like to do. Don't do it again.
iqueen
Forum Newbie
Posts: 8
Joined: Fri Jun 17, 2005 2:46 am

Post by iqueen »

sorry,
after i have pasted in regex board, I thought maybe I should post it in php code board.
:(
iqueen
Forum Newbie
Posts: 8
Joined: Fri Jun 17, 2005 2:46 am

Post by iqueen »

phpScott wrote:don't double post as you will get in trouble from the mods. :(
how to delete the post ?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

There's a little (x)-button on your post if you would wish to delete it. But since I've done it for you, there's nothing for you to do this time around.
iqueen
Forum Newbie
Posts: 8
Joined: Fri Jun 17, 2005 2:46 am

Post by iqueen »

patrikG wrote:There's a little (x)-button on your post if you would wish to delete it. But since I've done it for you, there's nothing for you to do this time around.
thanks.
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

It'd be possible to do this via range.

Basically, extract the stuff inside the brackets, split it, pop them into a range() to make an array, then loop through the new array to create your string. To get the double digit behaviour, you'd have to have it check the number of digits in the low number and use that to add extra 0s for single-digit numbers in the array.
iqueen
Forum Newbie
Posts: 8
Joined: Fri Jun 17, 2005 2:46 am

Post by iqueen »

Bennettman wrote:It'd be possible to do this via range.

Basically, extract the stuff inside the brackets, split it, pop them into a range() to make an array, then loop through the new array to create your string. To get the double digit behaviour, you'd have to have it check the number of digits in the low number and use that to add extra 0s for single-digit numbers in the array.
Thanks so much, that 's what I want.
Post Reply