Glad to be of service. 🙂
Well I guess the easiest methood would be to check the array to see how many strings are in it after the explode() function then act apon it. But why just stop with only checking for 1 entry, why not set up a reusable function to handle multiple entries.
~function.php~
<?php
function CreateUsername($fullname)
{
$array = explode(" ", $fullname);
if(count($array)==1)
$string = $array[0];
else
{
for($i=0;$i=count($array);$i++)
{
if(!$i) //if first entry only use first letter.
$string .= $array[$i][0];
else
$string .= '.'.$array[$i];
}
}
$string .= rand(0,999);
return $string;
}
?>
Of course if you've never worked with functions before I should probably give a brief example of how to use this within a script. It's pretty simple, but I know what it's like to be a newbie 🙂
~form.html~
<form method=post action="post.php">
<input type="text" name="name"><br>
<input type="submit">
</form>
~post.php~
<?php
include("function.php")
$username = CreateUsername($name);
echo 'Your username is "'.$username.'"';
?>
This is a great way to handle things if you want to be able to use this name generator in several scripts. 🙂