I have a bunch of urls like these.
$urls = array(
\'https://site1.com\',
\'https://www.site2.com\',
\'http://www.site3.com\',
\'https://sit
Depending on what exactly it is you want to do, it might be better to stick with PHP's own URL parsing facilities, namely parse_url:
foreach ($urls as &$url) {
$url = preg_replace('~^www.~', '', parse_url($url, PHP_URL_HOST));
}
unset($url);
parse_url will give you the host of the URL, even if it will contain a port number or HTTP authentication data. (Whether this is what you need, depends on your exact use case though.)