How can PHP string functions and regex be utilized to effectively split street addresses into street names and house numbers?

To split street addresses into street names and house numbers, we can utilize PHP string functions and regex. We can use regex to match the house number at the beginning of the address and extract it. Then, we can use string functions like substr to separate the street name from the house number.

$address = "123 Main Street";
$houseNumber = preg_replace('/\D/', '', $address); // Extract house number using regex
$streetName = trim(substr($address, strlen($houseNumber))); // Extract street name using substring
echo "House Number: " . $houseNumber . "<br>";
echo "Street Name: " . $streetName;