帝国cms小程序 帝国cms二次开发结合项url参数优化

帝国CMS教程

帝国官方结合项如果同一个字段不同值点击两次以上url就会出现重复的参数,当然对功能是没有影响的,感觉不大美观!

优化前:

/e/action/ListInfo.php?&classid=19&orderby=psalenum&myorder=1&ph=1&classid=19&pbrand=27&orderby=psalenum&myorder=1&myorder=1

优化后:

/e/action/ListInfo.php?classid=19&orderby=psalenum&myorder=1&ph=1&pbrand=27优化方法

在官方的结合项的函数方法echo $allstr;这行代码的前面插入以下代码即可:

 

//新增代码---jimmy.start-----preg_match_all('/<ahref="(.*?)".*?>(.*?)</a>/i',$allstr,$matches);for($i=0;$i<count($matches[1]);$i++){$url=$matches[1][$i];$parts=parse_url($url);$query=explode('&',$parts[query]);$output=array();foreach($queryas$key=>$value){if($value){$params=explode('=',$value);if($params[0]){$output[$params[0]]=urldecode($params[1]);}}}$newurl=$parts[path].'?'.http_build_query($output);$allstr=str_replace('href="'.$url.'"','href="'.$newurl.'"',$allstr);}//新增代码---jimmy.end-----

如果有多个结合项,可以把上面的代码放到一个函数里面调用方法就更加简单了,只需把echo $allstr;替换成echo beautifyUrl($allstr);即可

 

functionbeautifyUrl($allstr){//新增代码---jimmy.start-----preg_match_all('/<ahref="(.*?)".*?>(.*?)</a>/i',$allstr,$matches);for($i=0;$i<count($matches[1]);$i++){$url=$matches[1][$i];$parts=parse_url($url);$query=explode('&',$parts[query]);$output=array();foreach($queryas$key=>$value){if($value){$params=explode('=',$value);if($params[0]){$output[$params[0]]=urldecode($params[1]);}}}$newurl=$parts[path].'?'.http_build_query($output);$allstr=str_replace('href="'.$url.'"','href="'.$newurl.'"',$allstr);}//新增代码---jimmy.end-----return$allstr;}

 

 

标签: 帝国cms小程序