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
Submit Site
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 : Verifying / Correcting Addresses Grabbed From The YellowPages Example
Categories : PHP, CURL Click here to Update Your Picture
Joseph Crawford
Date : Dec 07th 2005
Grade : 5 of 5 (graded 1 times)
Viewed : 2741
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 
 

Ok so this really goes with the YellowPages example i showed however it is completely different so i opted to show it as a new example.

If you do any mailing for prospective clients you know mail has to be formatted to the USPS requirements for fast delivery and to ensure it doesnt bounce back to you. This is where address validation comes in.

I found an online demo to verify 1 address online
http://www.satorisoftware.com/US/addresscheck/AddressCheck.asp

I have since created a script that you can run, that will verify every address you have stored in your database.

I have not combined this with the YellowPages class but plan to integrate this so that it is a one step process

Here is the validate.php file

<?php
include_once('../global.php');
ini_set('max_execution_time', 9600);
function
Validate($address) {
 
$postedfields = 'AddressB='.urlencode($address['address']).'&AddressA=&city='.urlencode($address['city']).'&state='.urlencode($address['state']).'&zip='.urlencode($address['zip']).'&country=US&OptionA=True&OptionB=False&OptionC=True&Validated=True';
 
$ch = curl_init('http://www.satorisoftware.com/US/addresscheck/AddressCheck.asp');
 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
curl_setopt($ch, CURLOPT_POST, 1);
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postedfields);
 
curl_setopt($ch, CURLOPT_HEADER, 1);
 
curl_setopt($ch, CURLOPT_COOKIE, 1);
 
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
 
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
 
curl_setopt($ch, CURLOPT_REFERER, "http://www.satorisoftware.com/US/addresscheck/AddressCheck.asp");
 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'e:\htdocs\tmp\cookies\satorisoftware.cookiejar.txt');
 
$source = curl_exec($ch);
 
curl_close($ch);
  return
$source;
}

$rs = $db->Execute("SELECT id, address, city, state, zip FROM yp_records WHERE notes=''");
$rs->FirstRow();
while(!
$rs->EOF()) {
 
$src = validate($rs->fields);
 
preg_match_all('/<td  valign="top" class="TableCell">(.*?)<img src=\'/i', $src, $matches);
 
$addr = explode('<br>', $matches[0][0]);
 
$csz = explode(' ', $addr[1]);
 
$address['addr'] = strip_tags($addr[0]).' ';
  if(
count($csz) == 4) {
   
$csz[0] = $csz[0].' '.$csz[1];
    unset(
$csz[1]);
   
$csz = array_values($csz);
  }
 
$address['city'] = strip_tags($csz[0]);
 
$address['state'] = strip_tags($csz[1]);
 
$address['zip'] = strip_tags($csz[2]);   
 
preg_match_all('/Notes:<\/td>(.*?)<\/tr><tr>(.*?)<td colspan="2" class="TableCell" valign="top">(.*?)<\/td>/s', $src, $matches);
 
$notes = trim(strip_tags($matches[3][0]));
 
$db->Execute("UPDATE yp_records SET address='".$address['addr']."', city='".$address['city']."', state='".$address['state']."', zip='".$address['zip']."', notes='".$notes."' WHERE id=".$rs->fields['id']);
 
$rs->NextRow();
}
$rs->Close();
?>


Again you will have to use your own database logic.

Basically this sends the address/city/state/zip you have in your database to this site, and then grabs the correctly formatted version from the page source. It also grabs the notes so that you know what has happened if anything.

Some messages you may get are
Zipcode Changes
Address Changed
No Significant Changes

There are more errors but just showing a few so you get to know it ;)

Enjoy :)



These PHP Classes Check if a host is alive using various methods.
Categories : PHP, PHP Classes, Sockets, CURL
Import the yahoo address book.
Categories : PHP, CURL, Authentication
Newbie Notes #8 - A cron trick
Categories : PHP, CURL, Beginner Guides
A function to check if a URL exists
Categories : PHP, CURL, HTTP
curl_close -- Close a CURL session
Categories : PHP, PHP Functions, CURL
Yahoo! Messenger Friend List
Categories : PHP, CURL, HTML and PHP
Amazon.com API, CURL-REST Parser. Obtain data about Amazon products (PHP5 +)
Categories : PHP, Ecommerce, XML, Web Services, CURL
Using cURL to download a file programmatically.
Categories : PHP, PHP Extensions, CURL
PHP Youtube Downloader - This is a set of PHP functions that can be used to download movies from Youtube.com.
Categories : PHP, CURL, Regexps
Returns Yahoo! Address Book and Messenger List as an Array
Categories : PHP, PHP Classes, CURL
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Open remote https url using Curl and accept cookie
Categories : PHP, CURL
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
Sample AIM (Advanced Integration Method) PHP Script For Authorize.net using CURL
Categories : CURL, Ecommerce, PHP
Url To Pdf Report By Remote Application
Categories : PHP, PHP Classes, PDF, CURL