Maison > Article > développement back-end > 求该结果的preg_replace的轮换写法
求该结果的preg_replace的替换写法
$url=http://www.xxx.com/66/
preg_replace("#^\/(\d{2,4})\/?$#","name/index.php?t=1&id=$1",strtolower($url));
通过以上我能得到一个重写的网址:name/index.php?t=1&sid=66
我如何能直接通过一次正则替换,替换出一个数组:如下?
array(
'name'=>index.php,
'param'=>array('t'=>1,'id'=66)
);
$url = 'http://www.xxx.com/66/';<br />@preg_replace("#/(\d{2,4})/?$#e","\$t=array('name'=>'index.php','param'=>array('t'=>1,'id'=>$1))",strtolower($url));<br />print_r($t);<br />66Array
$url='http://www.xxx.com/66/';<br />$s= preg_replace("#\/(\d{2,4})\/?$#","/name/index.php?t=1&id=$1",strtolower($url));<br />$ar=parse_url($s);<br />$arr['name']=substr($ar['path'],strrpos($ar['path'],'/')+1);<br />parse_str($ar['query'],$t);<br />$arr['param']=$t;<br />print_r($arr);