-5

I have her a input text name="number1" , the user is ask to input integer and into the confirm.php i want to convert the integer i had enter in the index.php into roman numerals. if i input 1 it will echo to 'I' if 2 'II' etc . im desperate for my homework. still not familiar for scripting im new to php. anyway Thank you in advance

index.php:

<form  action="confirm_confirm.php" method="post">

  <input type="text" name="element1" >  

  <input type="text" name="number1" >

  <input type="text" placeholder="type" name="type1" >

  <input type="text" placeholder="metal type" name="metal_type" >

 <button type="submit" name="but" >Submit</button>
</form>   

And confirm.php:

<?php session_start(); ?>   
<?php

  $element1 = $_POST['element1'];
  $number1 = $_POST['number1'];
  $type1 = $_POST['type1'];
  $metal_type = $_POST['metal_type'];

    if($metal_type == "transition")
        {

                echo "$element1";

        }
    ?> 

1 Answers1

0

Here is a function to do so

<?php 
function romanNumerals($num){ 
    $n = intval($num); 
    $res = ''; 

    /*** roman_numerals array  ***/ 
    $roman_numerals = array( 
        'M'  => 1000, 
        'CM' => 900, 
        'D'  => 500, 
        'CD' => 400, 
        'C'  => 100, 
        'XC' => 90, 
        'L'  => 50, 
        'XL' => 40, 
        'X'  => 10, 
        'IX' => 9, 
        'V'  => 5, 
        'IV' => 4, 
        'I'  => 1); 

    foreach ($roman_numerals as $roman => $number){ 
        /*** divide to get  matches ***/ 
        $matches = intval($n / $number); 

        /*** assign the roman char * $matches ***/ 
        $res .= str_repeat($roman, $matches); 

        /*** substract from the number ***/ 
        $n = $n % $number; 
    } 

    /*** return the res ***/ 
    return $res; 
} 

echo romanNumerals(23); 
?>
Ayush Ghosh
  • 487
  • 2
  • 10