문제

Currently I am using parse_url, however the host item of the array also includes the 'WWW' part which I do not want. How would I go about removing this?

$parse = parse_url($url);
print_r($parse);
$url = $parse['host'] . $parse['path'];
echo $url;
도움이 되었습니까?

해결책

$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.

다른 팁

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', '', $parse['host']) . $parse['path'];
str_ireplace('www.','',$parse['host']); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top