Skip to content

Instantly share code, notes, and snippets.

@mwhooker
Forked from jessehattabaugh/gist:130964
Created June 17, 2009 00:20
Show Gist options
  • Save mwhooker/130998 to your computer and use it in GitHub Desktop.
Save mwhooker/130998 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);
$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