`$domain` can be `".example.com"` or `"example.com"`. `$domain = '.' . ltrim($domain, '.');` guarantees that `$domain` always will be in `".example.com"` form.