?
Solved

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

Posted on 2007-10-01
6
Medium Priority
?
6,949 Views
Last Modified: 2013-12-13
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!!!
0
Comment
Question by:joedunn
  • 3
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 19994494
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>
0
 

Author Comment

by:joedunn
ID: 19994731
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
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 19994821
Put this inside the page, changing "thisScript.php" to the name of the page:

<form METHOD=POST action="thisScript.php">
  <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 "$text<br>\n"; #display the answer
}
?>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:joedunn
ID: 19994964
So I need to create a second page called thisscript.php?
0
 
LVL 19

Expert Comment

by:Michael701
ID: 19995001
 $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
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 19995630
> 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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question