Created
June 16, 2009 22:58
-
-
Save jessehattabaugh/130964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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>…</li> | |
<li>JoeBob9</li> | |
<li>JoeBob10</li> | |
<li>…</li> | |
<li>JoeBob999999999</li> | |
<li>JoeBo1000000000</li> | |
<li>…</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