Skip to content

Instantly share code, notes, and snippets.

@jessehattabaugh
Created June 16, 2009 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jessehattabaugh/130964 to your computer and use it in GitHub Desktop.
Save jessehattabaugh/130964 to your computer and use it in GitHub Desktop.
<html><body>
<h1>Find a Unique Username</h1>
<p>With a limit of 15 characters</p>
<form method="get">
<label>First Name <input name="first_name" /></label>
<label>Last Name <input name="last_name" /></label>
<label>Quit after <input name="end" value="111" /></label>
<input type="submit" />
</form>
<h2>What I'm looking for</h2>
<ol>
<li>JoeBob</li>
<li>JoeBob0</li>
<li>&hellip;</li>
<li>JoeBob9</li>
<li>JoeBob10</li>
<li>&hellip;</li>
<li>JoeBob999999999</li>
<li>JoeBo1000000000</li>
<li>&hellip;</li>
<li>J99999999999999</li>
</ol>
<?php if($_GET['end']): ?>
<h2>Results</h2>
<ol>
<?php
// build userName
$userName = substr($_GET['first_name'].$_GET['last_name'], 0, 15);
// strip special characters
$userName = eregi_replace('[^a-zA-Z0-9_]', '', $userName);
// find a unique userName
do{
if(!isset($i)) $i=0;
else{ // add a number to the userName
if(strlen($userName)<15)
$userName = $userName.$i;
else
$userName = substr($userName, 0, 15-strlen($i)).$i;
$i++;
}
print "<li>$userName</li>";
} while($i<$_GET['end']);
?>
</ol>
<?php endif; ?>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment