|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
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 | |
|
|
|