I am trying to create a so-called Greek Numerals Converter tool. The input here will be letters and these letters will be converted into numbers. For every letter, there will be a corresponding number for it and also taking into consideration the digits. Now, my idea here is to create an array wherein all the letters and their corresponding numerical values will be put. So, when the user enters a combination of letters (up to 3 digits only), the convert() function will be looking for the corresponding values of those letters entered, get the values, and sum everything up. Unfortunately, as I went along the coding, I came up with this error (the one mentioned in the title) and I can't seem to figure out how to solve it. This might sound very stupid, but please do understand as I am still in the process of learning PHP.
Here are the codes that I was able to come up with.
<?php error_reporting(0);
class GreekNum
{
public function setText($text)
{
$this->text=$text;
}
public function getText()
{
return $this->text;
}
public function Convert($text)
{
$TextLength = strlen($text);
$text = strtoupper($text);
$text = str_split($text);
$collection = array(
"A" => 1,
"B" => 2,
"G" => 3,
"D" => 4,
"E" => 5,
"#" => 6,
"Z" => 7,
"Y" => 8,
"H" => 9,
"I" => 10,
"K" => 20,
"L" => 30,
"M" => 40,
"N" => 50,
"X" => 60,
"O" => 70,
"P" => 80,
"Q" => 90,
"R" => 100,
"S" => 200,
"T" => 300,
"U" => 400,
"F" => 500,
"C" => 600,
"$" => 700,
"W" => 800,
"3" => 900,
);
if(isset($text))
{
$total = 0;
for($i=0; $i<$TextLength; $i++)
{
if(array_key_exists($text[$i], $collection))
{
$total += $collection[$text[$i]];
}
if(end($text)!='.')
{
echo "Please make sure your line ends with a period. <br><br>";
return false;
}
}
return $total;
}
}
}
$GreekNum = new GreekNum();
$text = $_POST['text'];
$GreekNum->setText($text);
echo "<br>";
echo "<b>Entered Values: </b><br>". $GreekNum->getText();
echo "<br>";
echo "<br>";
echo "<b>Decimal Number Equivalence: </b><br/>". $GreekNum->Convert($text);
?>
The error is about the $total and I can't seem to figure out how to fix this. Any help would be very much appreciated. Thanks a lot!
This has been resolved already, but for the sake of whoever might need this, I'm editing this again to the code that currently works for me.