Hey fellow PHP-developers, i ran into some problems with a script / class, and i keep getting undefined when its defined in the include file.
Class.number.php
<?php
class DGSSeeker {
private $nummer, $navn, $adr, $postnr, $by;
function __construct($TelefonNummer){
$this->nummer = $TelefonNummer;
$this->GetData();
}
private function GetData(){
$data = preg_replace('/\s+\s+/','',file_get_contents("http://www.krak.dk/query?what=wp&search_word=".$this->nummer)); //This is the place where we search, its a danish service called Krak
preg_match('/<h2><span class="fn">(.*)<\/span><\/h2>/',$data,$dataNavn); //Its (.*) thats retrieved from the page. The bypass is to locate what we want to download - View the source code on the page you are looking from.
$this->navn = $this->StripIt($dataNavn[0]);
preg_match('/<span class="street-address">(.*)<\/span><br\/>/',$data,$dataAdr);
$this->adr = $this->StripIt($dataAdr[0]);
preg_match('/<span class="postal-code">(.*)<\/span><span class="locality">/',$data,$dataZip);
$this->postnr = $this->StripIt($dataZip[0]);
preg_match('/<span class="locality">(.*)<\/span><\/a>/',$data,$dataBy);
$this->by = $this->StripIt($dataBy[0]);
$data = null;
}
private function StripIt($str){
$str = strip_tags($str);
$str = str_replace(" ","",$str);
$str = str_replace(" ","",$str);
$str = str_replace("<span class=\"fn\">","",$str);
$str = str_replace("<span class=\"street-address\">","",$str);
return $str;
}
function getName() {return $this->navn;}
function getAdr() {return $this->adr;}
function getPostnr() {return $this->postnr;}
function getBy() {return $this->by;}
function getNummer() {return $this->nummer;}
}
?>
The index.php
<?php
include('class.number.php');
if($_SERVER['REQUEST_METHOD'] == "POST" && $_GET['Hent']) {
if($nummer == '') $status = '- You need to write a phone number.<br />';
if($status == '') {
$dgs = new DGSSeeker("$nummer"); //Number youre looking up
$navn = $dgs->getName();
$adresse = $dgs->getAdr();
$post = $dgs->getPostnr();
$by = $dgs->getBy();
$tlf = $dgs->getNummer();
}
else $status = 'The data couldnt be collected ' . $status . '';
}
?>
<form action="index.php?Hent=1" method="post">
Get information from Phone: <input type="text" size="8" maxlength="8" name="nummer" value="" /> <input type="submit" name="submit" value="Hent" />
</form>
<p>
<?php $status ?>
<br />
Navn: <input type="text" size="30" name="navn" value="<?php $navn ?>" />
<br />
Adresse: <input type="text" size="30" name="adresse" value="<?php $adresse ?>" />
<br />
Postnr.: <input type="text" size="30" name="post" value="<?php $post ?>" />
<br />
By: <input type="text" size="30" name="by" value="<?php $by ?>" />
<br />
Tlf.: <input type="text" size="30" name="tlf" value="<?php $tlf ?>" />
</p>
The code is danish itself, but it should be easy to understand, if anything i'll ofc translate the codes to english instead.
I just need some help on this and why it wont get the data, the query itself from http://www.krak.dk/query?what=wp&search_word=NUMBERHERE actually works, so it cant be that.
So can i request some help on this?