Hi,
I have the following code in C#.NET
Can anyone help to convert it to PHP? I am totally lost!
private int ValidateID(string input)
{
// Check length
if (string.IsNullOrEmpty(input) || input.Length != 9)
return 1;
if (int.Parse(input.Substring(2, 2)) > 12)
return 2;
int total = 0;
for (int i = 0; i < 8; i++)
total += int.Parse(input.Substring(i, 1)) * (9 - i);
int remainder = total % 11;
int digit9;
if (remainder < 2)
digit9 = 0;
else
digit9 = 11 - remainder;
if (digit9 != (int.Parse(input) % 10))
return 3;
return 0;
}
switch (ValidateID(sql_reader["id_number"].ToString()))
{
case 0: id_status = "Success"; break;
case 1: id_status = "Invalid length"; MessageBox.Show("Incorrect ID Number [ID Number length]", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Cursor = Cursors.Default; break;
case 2: id_status = "Invalid month"; MessageBox.Show("Incorrect ID Number [ID Number month]", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Cursor = Cursors.Default; break;
case 3: id_status = "Invalid number"; MessageBox.Show("Incorrect ID Number [ID Number number]", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Cursor = Cursors.Default; break;
default: id_status = "Unknown"; MessageBox.Show("Incorrect ID Number [unknown]", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Cursor = Cursors.Default; break;
}