Jump to content
Dragos

[PHP] Generate all combinations for a gmail username

Recommended Posts

  • Moderators
Posted (edited)

Gmail oferă posibilitatea de a avea adresa personală cu punct sau fără (mai multe info aici).

 

Prin scriptul următor se pot genera toate combinaţiile posibile pentru un ID dat.

 

<?php

/* 
Generate all combinations for a gmail username
Author: Dragos <dragos@interinfo.ro>
*/

$input = "person";

$emails = generate_gmail($input);

foreach($emails as $email)
	echo $email . "\n";

function generate_gmail($string)
{
	$chars = str_split($string);

	$input = array();
	for($i=0;$i<count($chars)-1;$i++)
		$input[] = array($chars[$i], $chars[$i] . ".");
	$input[] = array($chars[count($chars)-1]);

	$result = array();

	foreach ($input as $key => $values)
	{
		if (empty($values)) 
			continue;

		if (empty($result))
		{
			foreach($values as $value)
				$result[] = array($key => $value);
		}else{
			$append = array();

			foreach($result as &$product)
			{
				$product[$key] = array_shift($values);
				$copy = $product;

				foreach($values as $item) 
				{
					$copy[$key] = $item;
					$append[] = $copy;
				}

				array_unshift($values, $product[$key]);
			}

			$result = array_merge($result, $append);
		}
	}

	$final = array();

	foreach($result as $res)
		$final[] = implode("",$res) . "@gmail.com";

	return $final;
}

 

Edited by Dragos
  • Upvote 5

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...