Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    137

    Unanswered: make it PHP instead of C#

    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;
    }

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Let this be a lesson... comments in code are very useful!

    How are your PHP skills? If I gave you the pseudo code do you think you could manage it?
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2003
    Posts
    137
    Thank you. I did it.

    Appreciate it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •