<?
function get_zip_info($zip) { //Function to retrieve the contents of a webpage and put it into $pgdata
$pgdata =""; //initialize $pgdata
$fd = fopen("http://zipinfo.com/cgi-local/zipsrch.exe?zip=$zip","r"); //open the url based on the user input and put the data into $fd
while(!feof($fd)) {//while loop to keep reading data into $pgdata till its all gone
$pgdata .= fread($fd, 1024); //read 1024 bytes at a time
}
fclose($fd); //close the connection
if (preg_match("/is not currently assigned/", $pgdata)) {
$city = "N/A";
$state = "N/A";
}
else {
$citystart = strpos($pgdata, "Code</th></tr><tr><td align=center>");
$citystart = $citystart + 35;
$pgdata = substr($pgdata, $citystart);
$cityend = strpos($pgdata, "</font></td><td align=center>");
$city = substr($pgdata, 0, $cityend);
$statestart = strpos($pgdata, "</font></td><td align=center>");
$statestart = $statestart + 29;
$pgdata = substr($pgdata, $statestart);
$stateend = strpos($pgdata, "</font></td><td align=center>");
$state = substr($pgdata, 0, $stateend);
}
$zipinfo[zip] = $zip;
$zipinfo[city] = $city;
$zipinfo[state] = $state;
return $zipinfo;
}
if ( $_POST['zip'] == "" ) {
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="zip" maxlength="5" size="4">
<input type="submit" value="Find Zip Info">
</form>
<?
}
else {
$works = get_zip_info($_POST['zip']);
echo "Zip Code: ".$works[zip]."<br>City: ".$works[city]."<br>State: ".$works[state];
}
?>
Showing posts with label Using zip code get city state name using php. Show all posts
Showing posts with label Using zip code get city state name using php. Show all posts
Friday, December 7, 2012
Subscribe to:
Posts (Atom)
Popular Posts
-
Variables are important in every programming language — and it’s no different in PHP. Variables give developers the possibility of temp...
-
What? Hide the .php extension of your PHP files in the URL of your site address. Instead of: http://www.example.com/page.php Visitors to ...
-
Questions : 1 Who is the father of PHP ? Answers : 1 Rasmus Lerdorf is known as the father of PHP. Questions : 2 What is the...
-
Change Db settings here C:\xampp\htdocs\modx\core\xpdo\xpdo.class Line 2920 $this->config['dsn']= $dsn; $this->con...
-
<form action="" name="" method="post"> <p><b>user:</b> <input type="text...
-
Redirection is process of forwarding one URL to a different URL. There are three main kinds of redirects online; 301, 302 and meta refres...
-
Questions : 1 What is database or database management systems (DBMS)? and - What’s the difference between file and database? Can files...
-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script...
-
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Add More Elements...