Learning the Facebook Graph API

Earlier this month, I was approached by a software company to assist writing a Facebook application.  I hadn’t done this, however I have read about their powerful Graph API and was anxious to give it a shot. The first step was to learn to connect to the facebook API, which was greatly assisted by using the PHP SDK that has been written and released as open source. I’ll write a longer blog soon once I develop the application, but here’s the steps to begin writing your own external facebook application.

  1. Register your facebook application ( link )
  2. Download the Facebook PHP SDK (link)
  3. Read tutorials to learn the basics (click here for a good one)

Formatting Phone Number and Fixing User Input With PHP

Recently I was writing a franchise module for a shopping cart software that required franchise owners to input their phone number.  I’ve ran into the problem where no matter what instructions I’ve given, the franchise owners consistently like to format the phone number in their own unique way.  Rather than add 3 text boxes to where they have to tab between every part of the phone number, I wrote a quick and easy php script to handle all the leg work for me!

//Input example
//Output examples
//formatPhoneNum($phone_number, 1) outputs (999) 999-9999
// Inputting 999-9999 would cause the function to return “False”
function formatPhoneNum($phone_number, $style){
// Style 1 – (999) 999-9999
// Style 2 – 999-999-9999
// Style 3 – 999.999.9999
// Style 4 – 9999999999
$number = str_replace(array(‘(‘, ‘)’, ‘-‘, ‘ ‘), ”, $phone_number);
if (strlen($number) == 10){
$area = substr($number, 0, 3);
$first = substr($number, 3, 3);
$last = substr($number, 6);

case 1:
return “($area) $first-$last”;
case 2:
return “$area-$first-$last”;
case 3:
return “$area.$first.$last”;
case 4:
return “$area$first$last”;
// if the phone number was too long or too short
else {
return false;