All Combinations and Log?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
blksith0
Forum Newbie
Posts: 2
Joined: Mon Apr 11, 2011 6:16 pm

All Combinations and Log?

Post by blksith0 »

How would one put all combinations of an alphanumeric code into a URL bar and then log that? For example, www.google.com/sites/aaaaaa.html, www.google.com/sites/aaaaab.html, www.google.com/sites/aaaaac.html and so on and so on.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: All Combinations and Log?

Post by Weirdan »

Log?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: All Combinations and Log?

Post by fugix »

im not really sure how to automate the alpanumeric characters...but if you set all of them into an array and use a foreach() loop. you could echo every possibility into a url
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: All Combinations and Log?

Post by Jonah Bron »

Strings can be incremented in the manner you describe very easily. Here's some examples:

Code: Select all

$string = 'aaaaaa';
$string++;
echo $string; // outputs "aaaaab"

$string = 'aaaaaz';
$string++;
echo $string; // outputs "aaaaba"

$string = 'zzzzzz';
$string++;
echo $string; // outputs "aaaaaaa"; notice, now seven instead of six
And so on. So, to loop through all combinations would be very easy.

Code: Select all

for ($i = 'aaaaaa'; $i != 'aaaaaaa'; $i++) {
    // do something with $i
}
User avatar
blksith0
Forum Newbie
Posts: 2
Joined: Mon Apr 11, 2011 6:16 pm

Re: All Combinations and Log?

Post by blksith0 »

Thanks guys!
Post Reply