Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 23 lines (17 sloc) 0.633 kB
85ae7d3 @pezholio Updating code to reflect live site state
authored
1 <?php
2 function ernest_marples($postcode) {
3
4 $postcode = str_replace(" ", "", $postcode);
5
f368ce5 @ivebeenlinuxed Make code portable
ivebeenlinuxed authored
6 $url = "http://".$_SERVER['SERVER_NAME']."/postcode/". urlencode($postcode) .".csv"; // Build the URL
85ae7d3 @pezholio Updating code to reflect live site state
authored
7
8 $file = file_get_contents($url);
9
10 if (strpos($file, "html") === FALSE) { // Some error checking - if the file contains html, then we've been redirected to the homepage and something has gone wrong
11 $pieces = explode(",", $file);
12 $result['postcode'] = $pieces[0];
13 $result['lat'] = $pieces[1];
14 $result['lng'] = $pieces[2];
15 } else {
16 $result['error'] = TRUE; // If an error, return one
17 }
18
19 return $result;
20 }
21
22 print_r(ernest_marples("fdsdfs"));
23 ?>
Something went wrong with that request. Please try again.