Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/08/2010, 20:49
Avatar de mortiprogramador
mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 8 meses
Puntos: 214
Respuesta: Códigos - Reto Romanos

exangel

Código PHP:
Ver original
  1. <form action="romanos.php" method="post">
  2.     <input name="elnumero" type="text"><input name="" type="submit" value="enviar" maxlength="4">
  3. </form>
  4. <?php
  5. $elnumero_tx="";
  6. if(isset($_POST["elnumero"])){
  7.     if($_POST["elnumero"]!="" && is_numeric($_POST["elnumero"]) && intval($_POST["elnumero"])<10000){
  8.         $elnumero_tx=strval($_POST["elnumero"]);
  9.     }
  10. }
  11.  
  12. $entradas=array(1 => "I",
  13.                 2 => "II",
  14.                 3 => "III",
  15.                 4 => "IV",
  16.                 5 => "V",
  17.                 6 => "VI",
  18.                 7 => "VII",
  19.                 8 => "VIII",
  20.                 9 => "IX",
  21.                 10 => "X",
  22.                 40 => "XL",
  23.                 50 => "L",
  24.                 90 => "XC",
  25.                 100 => "C",
  26.                 400 => "CD",
  27.                 500 => "D",
  28.                 900 => "CM",
  29.                 1000 => "M"
  30.                 );
  31.                
  32. if($elnumero_tx!=""){
  33.     echo "<br>NÚMERO RECIBIDO: <strong>".$elnumero_tx."</strong><br>LA CONVERSIÓN A ROMANOS: <strong>";
  34.     if(strlen($elnumero_tx)==4) $num4=intval(substr($elnumero_tx,0,1));
  35.    
  36.     if(strlen($elnumero_tx)==3) $num3=intval(substr($elnumero_tx,0,1));
  37.     if(strlen($elnumero_tx)==4) $num3=intval(substr($elnumero_tx,1,1));
  38.    
  39.     if(strlen($elnumero_tx)==2) $num2=intval(substr($elnumero_tx,0,1));
  40.     if(strlen($elnumero_tx)==3) $num2=intval(substr($elnumero_tx,1,1));
  41.     if(strlen($elnumero_tx)==4) $num2=intval(substr($elnumero_tx,2,1));
  42.    
  43.     if(strlen($elnumero_tx)==1) $num1=intval(substr($elnumero_tx,0,1));
  44.     if(strlen($elnumero_tx)==2) $num1=intval(substr($elnumero_tx,1,1));
  45.     if(strlen($elnumero_tx)==3) $num1=intval(substr($elnumero_tx,2,1));
  46.     if(strlen($elnumero_tx)==4) $num1=intval(substr($elnumero_tx,3,1));
  47.    
  48.     if(strlen($elnumero_tx)>3){
  49.         if($num4>0){
  50.             for($h=1;$h<=$num4;$h++){
  51.                 echo $entradas[1000];
  52.             }
  53.         }
  54.    
  55.     }
  56.     if(strlen($elnumero_tx)>2){
  57.         if($num3>0){
  58.             if($num3<4){
  59.                 for($h=1;$h<=$num3;$h++){
  60.                     echo $entradas[100];
  61.                 }
  62.             }else{
  63.                 if($num3==4){
  64.                     echo $entradas[400];
  65.                 }else{
  66.                     if($num3==5){
  67.                         echo $entradas[500];
  68.                     }else{
  69.                         if($num3<=8){
  70.                             echo $entradas[500];
  71.                             for($h=1;$h<=($num3-5);$h++){
  72.                                 echo $entradas[100];
  73.                             }
  74.                         }else{
  75.                             echo $entradas[900];
  76.                         }
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.     }
  82.     if(strlen($elnumero_tx)>1){
  83.         if($num2>0){
  84.             if($num2<4){
  85.                 for($h=1;$h<=$num2;$h++){
  86.                     echo $entradas[10];
  87.                 }
  88.             }else{
  89.                 if($num2==4){
  90.                     echo $entradas[40];
  91.                 }else{
  92.                     if($num2==5){
  93.                         echo $entradas[50];
  94.                     }else{
  95.                         if($num2<=8){
  96.                             echo $entradas[50];
  97.                             for($h=1;$h<=($num2-5);$h++){
  98.                                 echo $entradas[10];
  99.                             }
  100.                         }else{
  101.                             echo $entradas[90];
  102.                         }
  103.                     }
  104.                 }
  105.             }
  106.         }
  107.     }
  108.     if($num1>0) echo $entradas[$num1];
  109.     echo "</strong>";
  110. }
  111. ?>
  112. <br /><br />
  113. <a href="romanos.zip">DESCARGAR PHP</a>
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com