I have the following if statement to check whether or not a string begins with http:// or https:// but I also need it to check whether it begins with www.
if (preg_match('#^https?://#i', $url) === 1) {
// Starts with http:// or https:// (case insensitive).
}
So the following would fail:
- http://www.website.com
- https://www.website.com
- http://website.com
- https://website.com
- www.website.com
But the following would pass the validation
- website.com
How can I adapt this to check for the above?