What are some best practices for handling host addresses with varying numbers of dots in PHP?

When handling host addresses with varying numbers of dots in PHP, a best practice is to use regular expressions to validate and extract the necessary information from the address. This can help ensure that the address is in a valid format before further processing. Additionally, using functions like `filter_var()` with the `FILTER_VALIDATE_IP` flag can help validate IP addresses.

$host = "192.168.1.1";

// Validate IP address using filter_var
if (filter_var($host, FILTER_VALIDATE_IP)) {
    echo "Valid IP address: " . $host;
} else {
    echo "Invalid IP address";
}