| Server IP : 104.21.17.213 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/gotofindhomes.com/components/Address/ |
Upload File : |
<?php
class Address {
public static function parse($address) {
$tblAdressState = new Address_State_Table();
$tblAdressZip = new Address_Zip_Table();
$arrRes = array('Zip' => '', 'State' => '', 'City' => '', 'County' => '','Address' => '', 'Unparsed' => '');
$address = trim($address, ' -');
$strZip = substr($address, -5);
$posDash = strpos($strZip, '-');
if ($posDash !== false) {
$address = substr($address, 0, strlen($address) - $posDash - strlen($strZip));
$strZip = substr($address, -5);
}
if (is_numeric($strZip)) {
$arrRes['Zip'] = $strZip;
$address = trim(substr($address, 0, strrpos($address, $strZip)));
}
$arrExplode = explode(',', $address);
if (count($arrExplode) == 3) {
$arrRes['State'] = trim($arrExplode[2]);
$arrRes['City'] = self::validateCity(trim($arrExplode[1]));
$arrRes['Address'] = trim($arrExplode[0]);
return $arrRes;
} elseif (count($arrExplode) == 2) {
$arrRes['State'] = (string) $tblAdressState->checkState(trim($arrExplode[1]));
if (!empty($arrRes['State'])) {
$address = trim(substr($address, 0, strrpos($address, $arrExplode[1])), ', ');
$checkCity = '';
$arrExplodeSpaces = explode(' ', $address);
$i = count($arrExplodeSpaces) - 1;
while (isset($arrExplodeSpaces[$i])) {
$checkCity = trim($arrExplodeSpaces[$i] . ' ' . $checkCity);
$CityCounty = $tblAdressZip->fetchCityAndCounty($checkCity, $arrRes['State']);
if (is_array($CityCounty)) {
$arrRes['City'] = $CityCounty['City'];
$arrRes['County'] = $CityCounty['County'];
if (!empty($arrRes['City'])) {
$arrRes['Address'] = trim(substr($address, 0, strrpos($address, $checkCity)), ', ');
break;
}
}
$i--;
}
if ($i < 0)
$arrRes['Unparsed'] = $address;
}
} else {
$arrRes['Unparsed'] = $address;
}
return $arrRes;
}
public static function validateCity($str) {
if (preg_match('/[0-9]+/', $str)) { // no numbers
return '';
} else {
return $str;
}
}
}