Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: G-Mail Dot Trick Generator

1. ## G-Mail Dot Trick Generator

It seems like a really simple concept, but I'm still baffled. I've actually been working on this little snippet for about 2 months now >.<.

What I'm trying to do:

Ok, you have a string "Cat". Now, you want to put periods in every possible combination in that string, except for before, and after the string. I NEED IT TO PRINT ALL POSSIBLE OUTCOMES, NOT JUST THE FINAL ^.^. So the possible outcomes are:

Cat
C.at
Ca.t
C.a.t

That math of it: !2^(n-1) == 2^(3-1) == 2^2 == 4

There's several ideas I have for going about this. Such as removing the first and last character, and adding white spaces in the entire string, then going about some kind of for loop (which I have no clue how it would work)...

Alright, Here's my plan of attack:

PHP Code:
``` <? // string string for dot placement \$string = "cat"; \$length = strlen(\$string); \$str1 = str_replace(\$string['0'],""); \$str2 = str_replace(\$string[\$length],""); \$newstring = \$str1 . "" . \$str2; \$newstrlen = strlen(\$newstring); for(\$i=0;\$i<=\$newstrlen;\$i++){ \$array = array("",".");  // to carry i } // and then.. the for loop // determine number of for loops and assign value for(\$l=0;\$l<=\$i;\$l++){ // Duh, doesn't work, but the concept is that this  // for loop is controlled from the other for loop, and // goes through the string once, then the other for  // loop goes through it the other time for(\$l=\$l;\$l <= \$i;\$l++){ // if it's a period, skip it if(\$newstring[\$l] = "."){ \$l = \$l++; } // if the letter is a number, or a letter, skip it elseif(ctype_alnum(\$newstring[\$l] !== false){ \$l = \$l++; } // if it's a white space, change to a period else{ \$newstring[\$l] = "."; } // end fors } }   ?> ```

As you can see, that will, in no way, work at all :P.

The thought behind it though is that if I take the first character, and the last character off, and then work with that string, it'll be better. The rest of it is the confusing part, the first part of the script works.

So, if you have any ideas on how to go about this, the algorithm, or anything like that, it'd be appreciated.

What is the G-Mail Dot Trick?

G-Mail uses a catch-all for emails like: "ca.t@gmail.com", it will send to "cat@gmail.com". The purpose for this ranges from several things, as it allows for multiple registrations on some sites, but all the emails come to the same address. It's rather effective. There's other methods as well, and I know that, but I need THIS method to work.

• Another method I'm attempting to use, and it looks like it might be on the right path:

PHP Code:
``` <?php// however if the string has 2 of the same characters, it messes up\$string = "howdy";// prevent a period at the very end of the string\$strlen = strlen(\$string) - 2;// print the base stringecho \$string . "<br />";// loop while i <= strlen, right before last characterfor(\$i=0;\$i<=\$strlen;\$i++){\$str = \$string[\$i];// put in the periods once after every \$i\$newstr = chunk_split(\$str,1,".");// try and do the first and last part of the string\$arr = explode(\$string[\$i], \$string, 2);// put it all togetherecho \$arr[0] . "" . \$newstr . "" . \$arr[1] . "<br />";}?> ```

It works exactly like it should, but I don't know where to go from there, right now, I get:

Code:
```howdy
h.owdy
ho.wdy
how.dy
howd.y```
And I need now:

Code:
```howdy
h.o.wdy
h.ow.dy
h.owd.y```
And so on.

Also, if there's more than one character, for instance "hwowdy", it outputs this:

Code:
```hwowdy
h.wowdy
hw.owdy
hwo.wdy
hw.owdy
hwowd.y```
As you can see, instead of putting it after the last 'w', it puts it after the first one. Dunno how to fix that too. =/.

Any help is appreciated !

EDIT: I'm trying to use implode to see if that works, but still no progress >.< // Implode didn't work .

• I'm not sure if this is the best way, but you can do it with binary.

Code:
```0000
howdy

0001
howd.y

...

1110
h.o.w.dy

1111
h.o.w.d.y```
PHP Code:
``` <?php \$string = "howdy"; header('Content-Type: text/plain'); \$string_length = strlen(\$string); \$combinations = pow(2, (\$string_length - 1)); // Loop through the number of combinations. for(\$i = 0; \$i < \$combinations; \$i++) {     // Use the current combination number to get the binary for the . positions.     \$bin = str_pad(decbin(\$i), (\$string_length - 1), '0', STR_PAD_LEFT);     echo \$bin . "\n";     // Loop through the binary number.     for(\$j = 0; \$j < (\$string_length - 1); \$j++)     {         // Output the current letter.         echo \$string[\$j];         // Output a . if the current binary column is positive.         if(\$bin[\$j] == 1)         {             echo '.';         }     }     // Output the last letter.     echo \$string[\$j] . "\n\n"; } ```

• ## Users who have thanked schleppel for this post:

Deacon Frost (03-01-2009)

• Seriously, thank you so freaking much.

I can only give one thanks, but if there was a way, I'd give so much more.

It works perfectly, and it doesn't really matter if it's not the normal way to approach it, as long as the outcome is accurate .

Thanks.

• PHP Code:
``` <?php\$string = 'howdy';\$separator = '.';echo \$string . '<br/>';\$strarray = str_split(\$string);\$strarray[0] .= \$separator;for (\$i = 1; \$i < count(\$strarray); \$i++) {    \$newarray = \$strarray;    \$newarray[\$i-1] .= (\$i > 1 ? \$separator : null);    echo implode('', \$newarray) . '<br/>';} ```
I responded to you on #php, but you were afk.

- haro

• PHP Code:
``` <?php function add_dot(\$str){   if(strlen(\$str) > 1){     \$ca = preg_split("//",\$str);     array_shift(\$ca);     array_pop(\$ca);     \$head = array_shift(\$ca);     \$res = add_dot(join('',\$ca));     \$result = array();     foreach(\$res as \$val){       \$result[] = \$head . \$val;       \$result[] = \$head . '.' .\$val;     }     return \$result;   }   return array(\$str); } \$res = add_dot('abracadabra'); print_r(\$res); ?> ```
best regards

• ## Users who have thanked oesxyl for this post:

Deacon Frost (03-02-2009)

• Thanks oesxyl ! Maybe I can find a way to combine the two .

Anyone wanting to see my end result :

http://ispikedthepunch.com/Deacons%2...te/dotrick.php

• What is the G-Mail Dot Trick?
I think you are not aware about the validity of email formats like
Code:
`D.....................eacon..............Frost@gmail.com`
You can have any(?) number of dots in between the characters.

• Originally Posted by abduraooft
I think you are not aware about the validity of email formats like
Code:
`D.....................eacon..............Frost@gmail.com`
You can have any(?) number of dots in between the characters.
Yeah, but think about it. If you were to write a script to allow only one submission per person, you'd allow one dot, but multiple dots would be picked up by any experienced coder :P.. Yeah, you can have multiple dots, you can also have example+<anynumber>@gmail.com, and it'll work. But if the scripts pick up special characters, it might not work. This method is nearly fool proof :P.

• Originally Posted by Deacon Frost
Yeah, but think about it. If you were to write a script to allow only one submission per person, you'd allow one dot, but multiple dots would be picked up by any experienced coder :P.. Yeah, you can have multiple dots, you can also have example+<anynumber>@gmail.com, and it'll work. But if the scripts pick up special characters, it might not work. This method is nearly fool proof :P.
your problem is interesting but in my opinion have nothing to do with mail addreses.
as far the address is valid acording to rfc's and exist somewhere on a server I don't see any reason to invent new rules.

best regards

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•