1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( ! class_exists( 'RealEstateTools' ) ) { |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* RealEstateTools class. |
7
|
|
|
*/ |
8
|
|
|
class RealEstateTools { |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* __construct function. |
12
|
|
|
* |
13
|
|
|
* @access public |
14
|
|
|
* @return void |
|
|
|
|
15
|
|
|
*/ |
16
|
|
|
public function __construct() { |
17
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* extract_zipcode function. |
22
|
|
|
* |
23
|
|
|
* @access public |
24
|
|
|
* @param mixed $address |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function extract_zipcode( $address ) { |
28
|
|
|
$zipcode = preg_match("/\b[A-Z]{2}\s+\d{5}(-\d{4})?\b/", $address, $matches); |
|
|
|
|
29
|
|
|
return $matches[0]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* extract_bed_count function. |
34
|
|
|
* |
35
|
|
|
* @access public |
36
|
|
|
* @param mixed $text |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function extract_bed_count( $text ) { |
40
|
|
|
$beds = preg_match("/\d (beds|Beds|Bedrooms)/", $text, $matches); |
|
|
|
|
41
|
|
|
$beds_text = $matches[0]; |
42
|
|
|
return $int = filter_var($beds_text, FILTER_SANITIZE_NUMBER_INT); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* extract_bath_count function. |
47
|
|
|
* |
48
|
|
|
* @access public |
49
|
|
|
* @param mixed $text |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function extract_bath_count( $text ) { |
53
|
|
|
$baths = preg_match("/\d (bath|Baths|Bathrooms)/", $text, $matches); |
|
|
|
|
54
|
|
|
$baths_text = $matches[0]; |
|
|
|
|
55
|
|
|
return $int = filter_var($beds_text, FILTER_SANITIZE_NUMBER_INT); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* validate_usa_zipcode function. |
60
|
|
|
* |
61
|
|
|
* @access public |
62
|
|
|
* @param mixed $zip_code |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function validate_usa_zipcode( $zip_code ) { |
66
|
|
|
if ( preg_match("/^([0-9]{5})(-[0-9]{4})?$/i", $zip_code) ) |
67
|
|
|
return true; |
68
|
|
|
else |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* is_valid_latitude function. |
75
|
|
|
* |
76
|
|
|
* @access public |
77
|
|
|
* @param mixed $latitude |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function is_valid_latitude($latitude) { |
81
|
|
|
if ( preg_match("/^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,6}$/", $latitude) ) { |
82
|
|
|
return true; |
83
|
|
|
} else { |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* is_valid_longitude function. |
91
|
|
|
* |
92
|
|
|
* @access public |
93
|
|
|
* @param mixed $longitude |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
public function is_valid_longitude($longitude) { |
97
|
|
|
if (preg_match("/^-?([1]?[1-7][1-9]|[1]?[1-8][0]|[1-9]?[0-9])\.{1}\d{1,6}$/", |
98
|
|
|
$longitude)) { |
99
|
|
|
return true; |
100
|
|
|
} else { |
101
|
|
|
return false; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.