WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : 411 Directory Assistance Scrape
Categories : PHP, PHP Classes Click here to Update Your Picture
Joseph Crawford
Date : Sep 30th 2005
Grade : 2 of 5 (graded 5 times)
Viewed : 7267
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

This script is used when you have a phone # and want to get the person's address.

extract.php
<?php
include_once('ReversePhoneLookup.php');

     
/**
     * ------------------------
     * Data scraper for 411.com
     * ------------------------
     *
     * Load the array with [valid] phone numbers.
     *
     */

$phone = array(
   
8027737566,
   
8027477118,
   
8024645557,
   
8023252200,
   
2025542400
);


     
/**
     *
     * Load the states array.
     *
     */
$states = array(
   
'AL' => 'Alabama',
   
'AK' => 'Alaska',
   
'AZ' => 'Arizona',
   
'AR' => 'Arkansas',
   
'CA' => 'California',
   
'CO' => 'Colorado',
   
'CT' => 'Connecticut',
   
'DE' => 'Delaware',
   
'DC' => 'D.C.',
   
'FL' => 'Florida',
   
'GA' => 'Georgia',
   
'HI' => 'Hawaii',
   
'ID' => 'Idaho',
   
'IL' => 'Illinois',
   
'IN' => 'Indiana',
   
'IA' => 'Iowa',
   
'KS' => 'Kansas',
   
'KY' => 'Kentucky',
   
'LA' => 'Louisiana',
   
'ME' => 'Maine',
   
'MD' => 'Maryland',
   
'MA' => 'Massachusetts',
   
'MI' => 'Michigan',
   
'MN' => 'Minnesota',
   
'MS' => 'Mississippi',
   
'MO' => 'Missouri',
   
'MT' => 'Montana',
   
'NE' => 'Nebraska',
   
'NV' => 'Nevada',
   
'NH' => 'New Hampshire',
   
'NJ' => 'New Jersey',
   
'NM' => 'New Mexico',
   
'NY' => 'New York',
   
'NC' => 'North Carolina',
   
'ND' => 'North Dakota',
   
'OH' => 'Ohio',
   
'OK' => 'Oklahoma',
   
'OR' => 'Oregon',
   
'PA' => 'Pennsylvania',
   
'RI' => 'Rhode Island',
   
'SC' => 'South Carolina',
   
'SD' => 'South Dakota',
   
'TN' => 'Tennessee',
   
'TX' => 'Texas',
   
'UT' => 'Utah',
   
'VT' => 'Vermont',
   
'VA' => 'Virginia',
   
'WA' => 'Washington',
   
'WV' => 'West Virginia',
   
'WI' => 'Wisconsin',
   
'WY' => 'Wyoming'   
);

$companies = array();

$lookup = new ReversePhoneLookup();

foreach(
$phone as $val) {

   
$data = $lookup->GetInfo($val);
   
array_push($companies, $data);
    unset(
$data);
}
echo
'<pre>', print_r($companies, 1), '</pre>';

?>



ReversePhoneLookup.php
<?php
class ReversePhoneLookup {

    public function
__construct() {

    }

    public function
GetInfo($number) {
        global
$states;
       
$ch =     curl_init("http://411.com/10668/search/Reverse_Phone?phone=".$number);

       
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       
curl_setopt($ch, CURLOPT_HEADER, 1);
       
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
       
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4");
       
curl_setopt($ch, CURLOPT_REFERER, "http://411.com/");
       
curl_setopt($ch, CURLOPT_COOKIEJAR, "411.cookie.txt");
       
curl_setopt($ch, CURLOPT_COOKIEFILE, "411.cookie.txt");

       
$data =    curl_exec($ch);
       
curl_close($ch);

       
/*     Technically could use one regex to match everything
        But There's a lot of html in between, so just cleaner to use two */

       
preg_match_all('#id="subtext"><span[^>]*><a[^>]*>(.*?)</a>#is', $data, $title);
       
preg_match_all('#<br><span\sid="subtext">((.*?)<br(?:\s/)?>)</span>#i', $data, $address);

        if(isset(
$title[1][0])) {
           
$title        = $title[1][0];
            if(
stristr($title, 'incorporated')) $title = str_ireplace('incorporated', 'Inc.', $title);
            if(
stristr($title, 'company')) $title = str_ireplace('company', 'Co.', $title);
           
$company['name'] = $title;
           
$address    = explode('<br>', $address[1][0]);
           
$address    = array_filter($address);
           
$addr_find = array(' rd', ' rd ', ' vt ', ' ave', ' ave ', ' st', ' st ');
           
$addr_replace = array(' Road', ' Road ', ' Vermont ', ' Avenue', ' Avenue ', ' Street', ' Street ');
           
$address[0] = str_ireplace($addr_find, $addr_replace, $address[0]);
            if(
strstr($address[0], ',')) {
               
$a = explode(',', $address[0]);
               
$company['address1'] = $a[0];
               
$addr_find = array('Apt', 'Ste.', 'Ste');
               
$addr_replace = array('Apt.', 'Suite', 'Suite');
               
$a[1] = str_ireplace('Apt', 'Apt.', $a[1]);
               
$a[1] = str_ireplace('Ste', 'Suite', $a[1]);
               
$company['address2'] = $a[1];
            } else
$company['address1'] = $address[0];

           
$csz = explode(" ", $address[1]);
            if(
strstr($csz[0], ',')) $company['city'] = substr($csz[0], 0, strlen($csz[0])-1);
           
$company['state'] = $states[$csz[1]];
            if(
$csz[2] == "") $company['zip'] = $csz[3];
            else
$company['zip'] = $csz[2];

           
$phone = explode(' ', $address[2]);
           
$company['phone'] = '1-'.substr($phone[0], 1, strlen($phone[0])-2).'-'.$phone[1];

            return
$company;
        }
    }
}
?>



very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
These PHP Classes Check if a host is alive using various methods.
Categories : PHP, PHP Classes, Sockets, CURL
an example of the cyberlib payment class
Categories : PHP, PHP Classes, Ecommerce, Credit Cards
Power Form Validation
Categories : PHP, PHP Classes, Data Validation
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
 Joseph Crawford wrote : 1355
Please note that 411.com limits the amount of data you can retrieve per day, if you wish to get more than that you can pay to use thier web service.
 
 Joseph Crawford wrote :1365
funny someone graded this example a 1 but never took the time to leave a comment as to why they did ;)