PHP Postcode Lookup & Address Auto-fill

Build a faster, more reliable UK postcode lookup service with surgical 1:1 property matching.

Why Postcode Lookup Matters!

 

For any UK-based application, a reliable postcode lookup is a core requirement. However, most standard address lookup tools overwhelm users with choice. When a UK postcode lookup API returns fifty similar addresses, users often select the wrong flat or number. This "choice friction" is a major hurdle in e-commerce and CRM data entry.

 

The findAddress.io approach refines the postcode to address search. By requiring a House Number/Name alongside the postcode, our API identifies the exact property footprint. This eliminates the need for long dropdown menus and ensures that your address lookup from postcode is 100% accurate every time. In this tutorial, we'll walk through how to build this functionality using PHP.


Step 1: The Postcode Lookup Interface

The first step in creating an effective postcode lookup form is capturing the specific identifiers needed for a 1:1 match. While generic tools only ask for a postcode, a precision UK address search requires a house number or name. This targeted input allows the backend to perform a direct query rather than a broad search. By validating these inputs on the frontend, you ensure that your postcode search API requests are efficient and yield a single, high-confidence result.

<!-- index.html -->
<form action="process.php" method="POST">
    <div class="form-group">
        <label>House Number or Name</label>
        <input type="text" name="house" required placeholder="e.g. 10">
    </div>
    
    <div class="form-group">
        <label>Postcode</label>
        <input type="text" name="postcode" required placeholder="e.g. SW1A 2AA">
    </div>
    
    <button type="submit" class="btn primary">Execute Postcode Lookup</button>
</form>

Step 2: Connecting to the Postcode Search API

Once the user submits their data, your PHP script must communicate with the postcode lookup API. Precision is key here; we use the http_build_query() function to construct the URL. This is essential for a UK postcode lookup because it handles the spaces and special characters common in British addresses. By encoding the apiKey, house, and postcode with proper delimiters, you guarantee that the findAddress engine receives a clean, actionable request for a single property record.

<?php
// process.php
$apiKey = "YOUR_API_KEY";
$house = $_POST['house'];
$postcode = $_POST['postcode'];

// Construct the postcode lookup query string with proper & delimiters
$params = http_build_query([
    'apiKey' => $apiKey,
    'house' => $house,
    'postcode' => $postcode
]);

$url = "https://findaddress.io/API/?" . $params;

// Execute the postcode to address search via file_get_contents
$response = file_get_contents($url);
$data = json_decode($response, true);
?>

Step 3: Processing Postcode Lookup Results

The final stage of your postcode lookup implementation is parsing the returned JSON payload. When the API finds a successful 1:1 match, it returns a detailed expandedAddress object. Unlike a basic postcode search that might just return a flat string, findAddress provides structured data—including the street, town, and county as separate keys. This allows you to auto-fill your database fields instantly, providing a seamless transition from a simple postcode entry to a fully verified and formatted customer record.

<?php
if ($data['result'] === "Success") {
    $addr = $data['expandedAddress'];
    
    // Map the verified postcode lookup data to your UI
    $street = $addr['street'];
    $town = $addr['town'];
    $county = $addr['County'];
    
    echo "Postcode Lookup Successful: " . $addr['house'] . " " . $street;
} else {
    // Handle cases where the combination doesn't exist
    echo "Lookup failed. Please check the house number and postcode.";
}
?>

Precision and Geodata

Speed and accuracy are the pillars of a successful integration. By utilizing a 1:1 matching engine, findAddress.io ensures that your application remains performant and your data remains clean. Every successful lookup also includes precise geodata (Latitude and Longitude), allowing you to go beyond simple text and implement mapping or delivery radius checks as part of your core postcode search functionality.

Start Your Postcode Lookup Integration

Implement a high-accuracy UK postcode search in minutes with our free developer tier.

Get API Key View API Docs