Area Code Lookup Script


/ Published in: PHP
Save to your folder(s)

This simple script will return what state an areacode belongs to. Be sure to get the include file that contains the array here: http://snipplr.com/view/17340/area-code-lookup-script--include-file/


Copy this code and paste it in your HTML
  1. <?php
  2. // ****************************************************** //
  3. // areacode.php -- Areacode Lookup Script //
  4. // //
  5. // Author: Brad Arnold -- http://arnoldb.com //
  6. // //
  7. // Licensed under Creative Commons - Share Alike //
  8. // Licensed under GPL2 //
  9. // //
  10. // This simple script will take an inputted area code //
  11. // and return the state in which the area code belongs. //
  12. // //
  13. // This file must be named areacode.php and the file //
  14. // areacodes.inc.php must reside in the same directory //
  15. // unless changes to the code are made. //
  16. // ****************************************************** //
  17.  
  18. if(!file_exists("areacodes.inc.php")) {
  19. die("ERROR! Areacode Data File is Missing or Corrupt!");
  20. }
  21. else {
  22. require("areacodes.inc.php");
  23. }
  24. ?>
  25.  
  26. <html>
  27. <head>
  28. <title>Area Code Lookup Utility</title>
  29. </head>
  30.  
  31. <body>
  32.  
  33. <!-- Begin Form -->
  34. <form action="areacode.php" method="get" onreset="doReset();">
  35. Area Code: <input type="text" name="fareacode" maxlength="3" size="2"/>
  36. <input type="submit" />
  37. <button onclick="form.reset();">Reset</button>
  38. </form>
  39.  
  40. <!-- Begin code -->
  41. <?php
  42. // Put GET data into variable for ease of use
  43. $input = $_GET["fareacode"];
  44.  
  45. // Check the variable, if empty show instructions, if in-use show results
  46. if ($input) {
  47. // If input doesn't match an Area Code in the array return and error
  48. if(empty($areacode[$input])) {
  49. echo "Sorry," . "&nbsp;" . "<a style=font-weight:bold; />" . $input . "</a>" . "&nbsp;" . "is not a valid Area Code.";
  50. }
  51. else echo "Area code" . "&nbsp;" . "<a style=font-weight:bold; />" . $input . "</a>" . "&nbsp;" . "is found in the state of:" . "&nbsp;" . "<a style=font-weight:bold; />" . $areacode[$input] . "</a>";
  52. }
  53. else echo "Enter a three (3) digit Area Code in the box above.";
  54. ?>
  55.  
  56. </body>
  57.  
  58. </html>

URL: http://www.arnoldb.com/2009/06/17/areacode-lookup-script/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.