Evaluate the replacement of the result preg_replace $ 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)
);
Reply to discussion (solution)
One step does not work. you need to analyze and form an array.
$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
)
)
$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);