Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/07/2007, 10:46
Avatar de Maxi.Net
Maxi.Net
 
Fecha de Ingreso: abril-2005
Ubicación: R.M. Talagante, Chile!!
Mensajes: 295
Antigüedad: 19 años, 1 mes
Puntos: 2
Re: Script para crear nombres de usuario

Muchas gracias por el apporte, gran aporte,
He agregado algunas cosas, que aparecen com MAYUSCULAS.

Gracias nuevamente y haber quien mas se anima para mejorar este script

Código PHP:
<?

function nombre_usuario($nombres,$apellidos)
{
    
// Separamos los Nombres
    
list($pri_nombre,$seg_nombre) = explode(" ",$nombres);
    
// Separamos los Apellidos
    
list($pri_apellido,$seg_apellido) = explode(" ",$apellidos);

   
// QUITAMOS LOS ESPACIOS EN BLANCO, EJEMPLO DE APELLIDO: DEL  CAMPO
   
$pri_nombrepreg_replace('/[ <>\'\"]/','',$pri_nombre); 
   
$seg_nombrepreg_replace('/[ <>\'\"]/','',$seg_nombre); 
   
$pri_apellidopreg_replace('/[ <>\'\"]/','',$pri_apellido); 
   
$seg_apellidopreg_replace('/[ <>\'\"]/','',$seg_apellido); 

    
// Ticket de Condicion
    
$username_encontrado FALSE;
    
$reglas 0;

    
$largo_nombre=strlen($pri_nombre);  //largo del nombre
    
$j=1//INDICA LA CANTIDAD DE CARACTERES A EXTRAER DEL NOMBRE

    // Mientras Encontremos un UserName
    
while ( !$username_encontrado )
    {
        
// Comenzamos con las Reglas
        
switch ($reglas)
        {
            
// Primer Nombre y Primer Apellido
            
case 0:
            
                
$username cortar_string(substr($pri_nombre,0,$j).$pri_apellido,12); //MANDAMOS LA CANTIDAD DE LETRAS ($J) DEL NOMBRE + EL APELLIDO (jperez,juperez,juaperez...)
                // Realizamos Consulta SQL
                
$sql "SELECT id FROM usuarios where username = '$username'";
                
// Aplicamos Consulta
                // Si existe registro, debemos cambiar el nick
                    
$j++; //SIGUIENTE CARACTER DEL NOMBRE
                    #MANTENGO LA REGLA HASTA TERMINAR CON TODAS LAS LETRAS DEL PRIMER NOMBRE
                   
if ($j $largo_nombre//SE USARON TODAS LAS LETRAS DEL PRIMER NOMBRE
                     
{
                     
$j=1//PARA COMENZAR CON LA PRIMERA LETRA DEL NOMBRE
                      
$reglas++; // Seguimos con la Otra Regla
                     
}
                  else 
                    {
                
// Si no Existen Registros
                    
$username_encontrado TRUE;
                    }
                            
            break;
            
            
// Primer Nombre Segundo Nombre Primer Apellido
            
case 0:
            break;
            
// Primer Nombre Primer Apellido Segundo Apellido
            
case 0:
            break;
            
            
// Regla de Numeros Al Azar
            
default:
            
$username cortar_strig($pri_nombre.$pri_apellido,10).rand(0,99);
            
// No Aumentamos la $reglas++ ya que esta es la ultima regla, de nombres con un numero al azar
            
            
        
}
        
        if ( 
$username_encontrado )
        {
            
// Encontramos el Nick
            // Insertamos en la BD
            // o lo retornamos en la Funcion
            
return $username;
        }
    
    
    }
}    

function 
cortar_string($s,$t
{
    return( 
substr($s,0,$t) );
}


?>
__________________
Amtez de enpezar kom otro idioma,
escrivamos vien el nueztro i como corezpomde. Jracias.

Última edición por Maxi.Net; 30/07/2007 a las 08:45 Razón: Gracias a la observación de Mickel (cortar_string(...))