Hello, I'm new into PHP. Just migrated from Java recently.
I'm trying to make a conversion machine that conver number to romans number.
Here is the code I wrote :
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latins to Romans Conversion</title>
</head>
<body>
<h2>Latin to Romans Conversion</h2>
<form method="post">
Input Your Number : <input type="text" name="number"><br><br>
<input type="submit" name="convert" value="submit">
<input type="reset" value="reset"><br><br>
<?php
if(isset($_POST['convert'])) {
$number = $_POST['number'];
function convertToRoman($number) {
function getNum($digit, $lowStr, $midStr, $nextStr) {
switch (true) {
case $digit <= 3: return str_repeat($lowStr, $digit);
case $digit == 4: return $lowStr + $midStr;
case $digit <= 8: return $midStr + str_repeat($lowStr, $digit);
default: return $lowStr + $nextStr;
}
}
$str = "0";
//Ribuan
$str += str_repeat("M", floor($number / 1000)) . $number %= 1000;
//Ratusan
$str += getNum(floor($number / 100), 'C', 'D', 'M') . $number %= 100;
//Puluhan
$str += getNum(floor($number / 10), 'X','L', 'C') . $number %= 10;
//Satuan
$str += getNum($number, 'I', 'V', 'X');
return $str;
}
$decimal = $number;
echo "The Roman's form of this decimal number is", convertToRoman($decimal);
return $decimal;
}
?>
</body>
</html>
It display these errors:
Warning: A non-numeric value encountered in D:\xampp\htdocs\omniwrench\latinromans.php on line 39
Warning: A non-numeric value encountered in D:\xampp\htdocs\omniwrench\latinromans.php on line 42
Anyway, I'm still using PHP 7. I tried declare of each romans value in an array like this (just example) :
$mapHundreds = array('M' => 1000);
Anyone got solution? I've been searching the problem about this for an hour now. Thanks!