Link to home
Start Free TrialLog in
Avatar of joedunn
joedunn

asked on

Convert a MAC Address to Numbers only - No letters - So it can be entered on a telephone

I need to have a simple form on a page that a user can enter a MAC Adress and have it 'translated' to the numbers the user would push on their telephone keypad to enter the number.  Very similar to a 1-800 number when the telephone number spells out a word - 1-800-GET-BEER would be 1-800-438-2337.  In this case however, it is much simpler as there are far fewer letters.

If someone could give me the whole html page from <html> to </html> that would be awesome!

Here are the basic rules for this translation:

i.      0  9 = 0  9
ii.      A = 22
iii.      B = 222
iv.      C = 2222
v.      D = 33
vi.      E = 333
vii.      F = 3333

So if I typed into the form:  000b8200e395  I would get the number -->  0002228200333395

The 'B' was converted to '222' and the 'E' was converted to '333' and the string was put back together.



Here is a link to a simple PHP page that does this with ASCII.

http://www.wallpaperama.com/tutorials/letter-converter.php (I just don't need ASCII)


Thanks!!!
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

You just need to change "thisScript.php" to the name of the script.

<html>
<form METHOD=POST action="thisScript.php">
  MAC Address: <INPUT TYPE="text" name="mac">
  <input type="submit">
</form>
<?php
if (isset($_POST['mac'])) {
  $text = $_POST['mac']; #"000b8200e395";
  echo "Before: $text<br>\n";
  $translation = array("A"=>"22",
                       "B"=>"222",
                       "C"=>"2222",
                       "D"=>"33",
                       "E"=>"333",
                       "F"=>"3333");
  foreach ($translation as $key => $value) {
    $text = preg_replace("@$key@i",$value,$text);
  }
  echo "After: $text<br>\n";
}
?>
</html>
Avatar of joedunn
joedunn

ASKER

SO CLOSE!!!

I have an existing page that I want to add this form to.  What do I need to do to make to it work righ inside an existing page?

_____________  Submit Button


_____________  <--- Display Answer
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joedunn

ASKER

So I need to create a second page called thisscript.php?
 $translation = array("A"=>"22",
                       "B"=>"222",
                       "C"=>"2222",
                       "D"=>"33",
                       "E"=>"333",
                       "F"=>"3333");

HUH? what if the MAC is 3DB2---
3332222
also the same as E2AA and many others

You'll need to take each 2 hex digits and convert them to 000 to 255
or
just convert the entire MAC  to one huge decimal number
> So I need to create a second page called thisscript.php?

No. Change the line:
<form METHOD=POST action="thisScript.php">
to use the name of the existing page for the action.

By the way, I don't know much about MAC addresses, so I can't say whether Michael701's comments mean that you'll need a change to get your code working.