稍后继续优化

<?php
function addWww($url){
	$parse = parse_url($url);

	$scheme = isset($parse['scheme'])?$parse['scheme']:'';
	$host = isset($parse['host'])?$parse['host']:'';
	$path = isset($parse['path'])?$parse['path']:'';
	$query = isset($parse['query'])?$parse['query']:'';
	$fragment = isset($parse['fragment'])?$parse['fragment']:'';

	preg_match('/^(([www]{3})|([\w]{1,}))[\.][\w]*?[\.][com|cn|com.cn|cc|net]{2,}/',$host,$match);

	if($match){
		$resUrl = $url;
	}else{
		$resUrl = $scheme.'://'.'www.'.$host.$path.'?'.$query.'#'.$fragment;
	}
	return $resUrl;
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注