日期:2014-05-17 浏览次数:20596 次
<?php
//url 格式 [1]
$txt="http://www.xxx.com/index.php/param1/test1/param2/test2/param3/test3";
//url 格式 [1-2]
// $txt="http://www.xxx.com/file/index.php/param1/test1/param2/test2/param3/test3";
//url 格式 [2]
//$txt="http://www.xxx.com/index.php/param1-test1-param2-test2-param3-test3";
$pattern="/(?<!\/)\/(?!\/)/";
$chars = preg_split($pattern, $txt, -1, PREG_SPLIT_NO_EMPTY);
$chars=array_slice($chars,2);
echo "<pre>";
var_dump($chars);
?>
$s = 'param1/test1/param2/test2/param3/test3';
$t = preg_replace('#([^/]+)/([^/]+)/?#', '&$1=$2', $s);
parse_str($t, $ar);
print_r($ar);
------解决方案--------------------
你这个用的是CI?
$this->uri->segment(n)
它允许你重新分割一个详细的URI分段。 n 为你想要得到的段数。分割数按照从左至右的顺序编排。
------解决方案--------------------
楼主搞框架啊。我直接explode('/', $url);
------解决方案--------------------
$this->uri->segment(n)
CI是这个方法
ci是这样处理的:
explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))
不过我会采用 explode 这个方式了。