Find the replacement method of the result preg_replace $ urlwww. xxx. com66preg_replace (# ^ (d {2, 4 })? $ #, Nameindex. php? T1 & amp;, strtolower ($ url); through the above, I can get a rewrite url: nameindex. php? T1 & amp; sid6
$ Url = http://www.xxx.com/66/
Preg_replace ("# ^ \/(\ d {2, 4 })\/? $ # "," Name/index. php? T = 1 & id = $1 ", strtolower ($ url ));
Through the above, I can get a rewritten URL: name/index. php? T = 1 & sid = 66
How can I replace an array with a regular expression?
Array (
'Name' => index. php,
'Param' => array ('t' => 1, 'id' = 66)
);
------ Solution --------------------
One step does not work. you need to analyze and form an array.
------ Solution --------------------
$url = 'http://www.xxx.com/66/';
@preg_replace("#/(\d{2,4})/?$#e","\$t=array('name'=>'index.php','param'=>array('t'=>1,'id'=>$1))",strtolower($url));
print_r($t);
66 Array
(
[Name] => index. php
[Param] => Array
(
[T] => 1
[Id] => 66
)
)
------ Solution --------------------
$url='http://www.xxx.com/66/';
$s= preg_replace("#\/(\d{2,4})\/?$#","/name/index.php?t=1&id=$1",strtolower($url));
$ar=parse_url($s);
$arr['name']=substr($ar['path'],strrpos($ar['path'],'/')+1);
parse_str($ar['query'],$t);
$arr['param']=$t;
print_r($arr);