-
-
Save mwhooker/130998 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); | |
$upperLimit = intval($_GET['end']); | |
$pattern = '/([0-9])+$/'; | |
$matches_n = preg_match($pattern, $userName, $matches); | |
if ($matches_n > 0) { | |
$n = $matches[0]; | |
$userName = preg_replace($pattern, '', $userName); | |
} else { | |
$n = 0; | |
} | |
while ($n < $upperLimit) { | |
++$n; | |
echo $userName . $n . "<br />"; | |
} | |
?> | |
</ol> | |
<?php endif; ?> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment