pastebin - collaborative debugging tool
kpaste.net RSS


Untitled
Posted by Anonymous on Sun 13th Apr 2014 06:35
raw | new post
modification of post by Anonymous (view diff)

  1. <?php
  2. error_reporting(~E_NOTICE);
  3. $handle = fopen("postcodes.txt", "r");
  4. if ($handle) {
  5.     while (($postcode = fgets($handle)) !== false) {
  6.         $postcode = trim($postcode);
  7.         if (empty($postcode)) continue;
  8.                 $ch = curl_init();
  9.                 $url = "http://www.dslchecker.bt.com/pls/adsl/ADSLChecker.AddressOutput?URL=&SP_NAME=a%20service%20provider&postcode=$postcode&VERSION=29&MS=E&CAP=yes&AEA=N";
  10.                 curl_setopt($ch, CURLOPT_URL, $url);
  11.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  12.                 $result = curl_exec($ch);
  13.                 curl_close($ch);
  14.                
  15.                 $dom = new DOMDocument();
  16.                 @$dom->loadHTML($result);
  17.                 $finder = new DomXPath($dom);
  18.                 $nodes = $finder->query("//option");
  19.                
  20.                 foreach ($nodes as $node) {
  21.                         if ($node->nodeValue == "Please select your address from the list below.") continue;
  22.                 $address = preg_split("/, /", $node->nodeValue);
  23.                 $firstline = $address[0];
  24.                 if (preg_match("/^\d+.*/", $firstline)) {
  25.                         preg_match("/^\d+/", $firstline, $number);
  26.                         $addresses[] = array(
  27.                                 "number" => $number[0],
  28.                                 "postcode" => $postcode,
  29.                                 );
  30.                                 unset($number);
  31.                         } else {
  32.                                 if (preg_match("/^\d+.*/", $address[1])) preg_match("/^\d+/", $address[1], $number);
  33.                                 $addresses[] = array(
  34.                                 "name" => $firstline,
  35.                                 "number" => $number[0],
  36.                                 "postcode" => $postcode,
  37.                                 );
  38.                                 unset($number);
  39.                         }
  40.         }
  41.         }
  42. }
  43.  
  44. foreach ($addresses as $address) {
  45.         ob_start();
  46.         $number = $address["number"];
  47.         $name = $address["name"];
  48.         $postcode = $address["postcode"];
  49.         echo "$postcode\r\n";
  50.         $ch = curl_init();
  51.         $url = "http://www.dslchecker.bt.com/pls/adsl/ADSLChecker.AddressOutput?URL=&SP_NAME=a%20service%20provider&postcode=$postcode&buildingnumber=$number&buildingname=$name&VERSION=29&MS=E&CAP=yes&AEA=N";
  52.         curl_setopt($ch, CURLOPT_URL, $url);
  53.         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  54.         $result = curl_exec($ch);
  55.         curl_close($ch);
  56.         preg_match("/Address.*is served by Cabinet (\d+)/si", $result, $matches);
  57.         $cabinet = $matches[1];
  58.         echo "$name, $number, $postcode. Cabinet: ".($cabinet ? $cabinet : "EO")."\r\n";
  59.         ob_flush();
  60. }      
  61. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at