-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpblm.php
69 lines (57 loc) · 1.62 KB
/
phpblm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Parser for Rightmove's lovely BLM files.
*/
class phpblm {
private $blm;
private $header = array();
private $def = array();
private $data = array();
public function __construct($file) {
$this->blm = file_get_contents($file);
$this->splitPieces();
}
// Return specific field from row
public function getData($data, $row) {
return $this->data[$row][$data];
}
// Return header info
public function getHeader($hdr) {
return $this->header[$hdr];
}
// This will return the actual number of properties, regardless of what the
// header might say. To retrieve the header value (if present), use:
// $blm->getHeader('Property Count');
public function propCount() {
return count($this->data);
}
public function properties() {
return $this->data;
}
// Splits the BLM data into constituent parts
private function splitPieces() {
$pieces = explode("#", $this->blm);
// Get the header (includes EOF/EOR stuff)
$header = explode("\n", trim($pieces[2]));
foreach ($header as $h) {
$h = preg_replace("/\'/", "", $h); // Remove quotes on EOF/EOR
$h_pieces = explode(" : ", $h);
$this->header[trim($h_pieces[0])] = trim($h_pieces[1]);
}
// Get the definitions
$def = explode($this->header['EOF'], trim($pieces[4]));
foreach ($def as $d) {
$this->def[] = $d;
}
// Get the data
$data = explode($this->header['EOR'], trim($pieces[6]));
$datac = count($data);
for ($i=0; $i<$datac; $i++) {
$row = explode($this->header['EOF'], trim($data[$i]));
for ($j=0; $j<count($row); $j++) {
$row_arr[$this->def[$j]] = $row[$j];
}
$this->data[] = $row_arr;
}
}
}