How can you verify if a string has a valid IP format in PHP?

To verify if a string has a valid IP format in PHP, you can use the `filter_var` function with the `FILTER_VALIDATE_IP` filter option. This function will check if the string is a valid IP address in either IPv4 or IPv6 format.

$ip = "192.168.1.1";

if (filter_var($ip, FILTER_VALIDATE_IP)) {
    echo "Valid IP address";
} else {
    echo "Invalid IP address";
}