PHP script to properly format phone numbers

Summary: One of the biggest challenges as a programmer lies in the fact that you have to think ahead for your users so that things work seamlessly.  On any site involving input fields that interact with a database, it is critical that the information be validated before going into the database, and with a bit of forethought you can make sure that the inputs are not only valid, but in a standardized format. Consider phone numbers as an example.  If you ask 10 people to write down their phone numbers, you might get several different responses:

  • 555.5555
  • 555-5555
  • 555.555.5555
  • 555-555-5555
  • (555)555.5555
  • (555)555-5555
  • 5555555
  • 5555555555
  • 1.555.555.5555
  • 1-555-555-5555
  • 1(555)555.5555
  • 1(555)555-5555
You get the idea.
Concept:  While you could write code that forces users to type in the phone number a certain way, you can also... Read more »

How to Detect a Default Gravatar Image for an Email Address – PHP Tutorial

Summary:  Have you ever liked a site so much that you created an account on their website by giving them your email and creating a password, only to login and find that they already had a picture of you on file?  How do that do that?!   This intelligent design utilizes a free web service called Gravatar (or similar concept). Concept:  To obtain your Gravatar, use PHP to create the md5 hash of the email address of interest and append that hash to:[insert-hash-here].jpg.  There are a lot of available options for the type of image that is called (by passing GET parameters) from the Gravatar servers that can adjust the size, type, etc of the image. Problem: I... Read more »