PHP: Remove 'WWW' from URL inside a String
preg_replace('#^(http(s)?://)?w{3}\.#', '$1', $url);
if you don't need a protocol prefix, leave the second parameter empty
$url = preg_replace('#^www\.(.+\.)#i', '$1', $parse['host']) . $parse['path'];
This won't remove the www
in www.com
, but www.www.com
results in www.com
.