<?php
class TBonlineSearch {
function __construct() {
if(!http_support(HTTP_SUPPORT_REQUESTS)) {
die("TBonlineSearch: Need HTTP request support!\n");
}
}
// geotype can be: ort | bezirk | bland
function lookup($name, $geo, $geotype = "ort") {
if(empty($name)) die("lookup(): No name given.\n");
if(empty($geo)) die("lookup(): No geo-information given.\n");
$fields = array(
'pc' => 'tb',
'was' => '',
'telnummer' => '',
'suchmaske' => '_einfach',
'aktion' => 'suchetb',
'loga' => '',
'selsort' => '',
'AktuelleSeite' => '0',
'blaettern' => '_einfach',
'karte' => 'nichtanzeigen',
'wen' => $name,
'geowahl' => $geotype,
'wo' => $geo
);
$response = http_post_fields("http://www.tb-online.at/index.php", $fields);
preg_match_all('/\<div class\=\"adresse\"\>(.*?)\<\/div\>/s', $response, $matches);
if(!count($matches[1])) {
return false;
}
$ret = array();
foreach($matches[1] as $key) {
preg_match_all('/\<p class\=\"name\"\>(.*?)\<\/p\>/', $key, $x);
preg_match_all('/\<p class\=\"telnummer\"\>(.*?)\<\/p\>/', $key, $y);
$name = $x[1][0];
$numbers = split('<br />', $y[1][0]);
$numbers = str_replace(array(' ', '/', '-'), '', $numbers);
$ret[] = array(
'name' => $name,
'numbers' => $numbers
);
}
return $ret;
}
function reverseLookup($num) {
if (empty($num)) die("reverseLookup(): No number given.\n");
$fields = array(
'pc' => 'in',
'suchmaske' => '_einfach',
'aktion' => 'suchein',
'loga' => '',
'selsort' => '',
'AktuelleSeite' => '0',
'blaettern' => '_einfach'.$num,
'wen' => '',
'was' => '',
'wo' => '',
'karte' => 'nichtanzeigen',
'telnummer' => $num
);
$response = http_post_fields("http://www.tb-online.at/index.php", $fields);
preg_match_all('/\<p class\=\"name\"\>(.*)\<\/p\>/', $response, $matches);
if(count($matches[1]) < 1) {
return false;
} else if (count($matches[1]) >= 1) {
return $matches[1];
}
}
}
?>