Comunidad de diseño web y desarrollo en internet online

Generación de Nicknames

Citar            
MensajeEscrito el 02 Sep 2009 06:56 pm
Hola, necesito crear un generador de nicknames, algo así como en algunas páginas en donde si el nick ya existe dan un listado de sugerencias con nicks disponibles y que ha generado automáticamente, pero no estoy realmente seguro del flujo de funcionamiento para poder generarlos, no necesito directamente el código, así que cualquier idea será bien recibida!...

Gracias!

Por Rudy3001

69 de clabLevel



 

Por los grandes paisajes de Guatemala

firefox
Citar            
MensajeEscrito el 03 Sep 2009 06:51 am
Puedes intentar tomando algunos datos del usuario, como el nombre o el nickname que escribió anteriormente, y le agregas un número aleatorio generado por tu script. Luego haces una consulta rápida a la base de datos para confirmar que el nick generado no existe aún y listo.

Por Odin

Claber

639 de clabLevel

2 tutoriales

Genero:Masculino   Premio_Secretos

El valle de las hamacas

mozilla
Citar            
MensajeEscrito el 03 Sep 2009 03:57 pm
Había estado pensando en algo similar y esto creo que lo confirma, cuando lo termine lo posteo aquí por si alguien lo llega a necesitar :-)... gracias siempre!

Por Rudy3001

69 de clabLevel



 

Por los grandes paisajes de Guatemala

safari
Citar            
MensajeEscrito el 09 Sep 2009 11:07 pm
por si alguien lo necesita, aún le falta una pulida y que pregunte en la Base de Datos pero esto es más sencillo... a ver si algún día le acorta el tiempo a alguno...

Código PHP :

<?php
   if(isset($_POST['go'])){

      //Catch user info
      $user_info = array($_POST['myName'],$_POST['last']);
      $nick = $_POST['nick'];

      //Define some keywords to use
      $start   = explode(',','my,the,el,nuevo,best');
      $end     = explode(',','online,best,now');
      $symbols = explode(',','.,_,');
   
      $endOrStart = array($start,$end);
      $nickOrName = array($nick, $user_info);
         
      for($i=0;$i<200;$i++){

         //Shuffle the array's content
         shuffle ($start);
         shuffle ($end);
         shuffle ($symbols);
      
         //Choose between Start or End word
         $firstPartIndex  = array_rand($endOrStart);
         $firstPartOption = $endOrStart[$firstPartIndex];
         if($firstPartIndex == 0){
            $startPart = $firstPartOption[rand(0,count($firstPartOption)-1)];
         }else{
            $endPart = $firstPartOption[array_rand($firstPartOption)];
         }
         
         $num = rand  ( 10 , 99 );
         $max_in = count($symbols)-1;

         //Choose between the User Name Info or the Nickname
         $secondPartIndex  = array_rand($nickOrName);

         if($secondPartIndex == 0){
            //Play with nickname
            if($firstPartIndex){
               $nick_suggest[] = $nick.$symbols[rand(0,$max_in)].$endPart;
            }else{
               $nick_suggest[] = $startPart.$symbols[rand(0,$max_in)].$nick;
            }
         }else{
            //Play with User Info
            shuffle( $user_info );

            //Build suggestions with Name and Last Name
            if($firstPartIndex){
               $nick_suggest[] = $user_info[0].$symbols[rand(0,$max_in)].$endPart;
            }else{
               $nick_suggest[] = $startPart.$symbols[rand(0,$max_in)].$user_info[1].$symbols[rand(0,$max_in)].$num;
            }
            
         }
      }
      
      $result = array_unique($nick_suggest);
      shuffle($result);
   }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    Nombre: <input type="text" name="myName" id="myName" />
  </p>
  <p>
    Apellido: <input type="text" name="last" id="last" />
  </p>
  <p>
    Nickname: <input type="text" name="nick" id="nick" />
  </p>
  <input name="go" id="go" type="submit" value="Enviar" />
</form>
    <ol>
      <?php
            for($i=0; $i<10; $i++){
                echo '<li>'.$result[$i].'</li>';
            }
        ?>
    </ol>
</body>
</html>


Cualquier idea para comprimirlo un poco o hacerlo más eficiente es recibida con mucha alegría :P :wink:

Saludos.

Por Rudy3001

69 de clabLevel



 

Por los grandes paisajes de Guatemala

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.