<?php
$string="http://www.abc.com/news/detail.php?cid=c1&id=8";
$re="#(.*\/)+\w+\.\w+(((\?|\&)\w+\=\w+)+)#si";
preg_match($re,$string,$out);
preg_match_all("#\=(\w+)#si",$out[2],$OUT);
for($i=0;$i<count($OUT[1]);$i++){
$url.=$OUT[1][$i]."/";
}
$url=$out[1].$url;
echo $url; //http://www.abc.com/news/c1/8/ ,用parse_url()函数其实更简单
?>
$string="http://www.abc.com/news/detail.php?cid=c1&id=8";
$re="#(.*\/)+\w+\.\w+(((\?|\&)\w+\=\w+)+)#si";
preg_match($re,$string,$out);
preg_match_all("#\=(\w+)#si",$out[2],$OUT);
for($i=0;$i<count($OUT[1]);$i++){
$url.=$OUT[1][$i]."/";
}
$url=$out[1].$url;
echo $url; //http://www.abc.com/news/c1/8/ ,用parse_url()函数其实更简单
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货