Hello,
I am working on a program which parses street addresses and then compares them to a database. The problem is different notations for the house number. Most residential neighborhoods use dashed numbers ('94-078') for the address. However, the database stores numbers by replacing the dash with an extra zero ('940078'). So I need to check if there is a dash in the number, and then replace that dash with a zero.
Here's what I have so far: (including some comments and variable watches)
// parse address number
$parts_array = explode(" ", $address);
if ($parts_array[0] > 0) { // first piece of address is a number
$number = $parts_array[0];
if (preg_match("/\d-\d/", $number)){
echo "pregmatch works";
$number = preg_replace("/\d-\d/", "/\d0\d/", $number);
echo "number is $number";
}
} else {
echo "This address does not seem to begin with a number";
exit;
}
Currently, the preg_match statement appears to be working. But the preg_replace is a disaster. Any assistance on this would be greatly appreciated.