Difference between
modified post 108c by Anonymous on Sun 13th Apr 2014 05:57
original post f4b52687a by Anonymous on Sun 13th Apr 2014 05:23
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | <?php | |
| 2 | 2 | $handle = fopen("postcodes.txt", "r"); | |
| 3 | 3 | if ($handle) { | |
| 4 | 4 | while (($postcode = fgets($handle)) !== false) { | |
| 5 | 5 | $postcode = trim($postcode); | |
| 6 | 6 | if (empty($postcode)) continue; | |
| 7 | 7 | $ch = curl_init(); | |
| 8 | 8 | $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"; | |
| 9 | 9 | curl_setopt($ch, CURLOPT_URL, $url); | |
| 10 | 10 | curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); | |
| 11 | 11 | $result = curl_exec($ch); | |
| 12 | 12 | curl_close ($ch); | |
| 13 | 13 | ||
| 14 | 14 | $dom = new DOMDocument(); | |
| 15 | 15 | @$dom->loadHTML($result); | |
| 16 | 16 | $finder = new DomXPath($dom); | |
| 17 | 17 | $nodes = $finder->query("//option"); | |
| 18 | 18 | ||
| 19 | 19 | foreach ($nodes as $node) { | |
| 20 | - | echo $node->nodeValue."\r\n"; | |
| 20 | + | if ($node->nodeValue == "Please select your address from the list below.") continue; | |
| 21 | - | } | |
| 21 | + | $address = preg_split("/, /", $node->nodeValue); | |
| 22 | - | } | |
| 22 | + | $firstline = $address[0]; | |
| 23 | - | } | |
| 23 | + | if (preg_match("/^\d+.*/", $firstline)) { | |
| 24 | - | ||
| 24 | + | preg_match("/^\d+/", $firstline, $number); | |
| 25 | - | ?> | |
| 25 | + | echo "$number[0], $postcode\r\n"; | |
| 26 | - | ||
| 26 | + | unset($number); | |
| 27 | - | ||
| 27 | + | } else { | |
| 28 | - | ||
| 28 | + | $number = 0; | |
| 29 | - | ||
| 29 | + | $names[] = $firstline; | |
| 30 | - | ||
| 30 | + | if (preg_match("/^\d+.*/", $address[1])) preg_match("/^\d+/", $address[1], $number); | |
| 31 | - | ||
| 31 | + | echo "$firstline, $number[0], $postcode\r\n"; | |
| 32 | - | ||
| 32 | + | unset($number); | |
| 33 | - | ||
| 33 | + | } | |
| 34 | - | ||
| 34 | + | } | |
| 35 | - | ||
| 35 | + | } | |
| 36 | - | ||
| 36 | + | } | |
| 37 | - | ||
| 37 | + | ?> |
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.
kpaste.net RSS