首頁  >  文章  >  後端開發  >  请问【框架爱好者们】地址栏参数的简易获取方式

请问【框架爱好者们】地址栏参数的简易获取方式

WBOY
WBOY原創
2016-06-13 10:08:57740瀏覽

请教【框架爱好者们】地址栏参数的简易获取方式。

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?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 class="brush:php;toolbar:false">";    var_dump($chars);?>


碰到这些url写法,你们的获取方式是怎么样的,探讨探讨



------解决方案--------------------
不太清楚你的意思
形如 http://www.xxx.com/index.php/param1/test1/param2/test2/param3/test3 的url在 $_SERVER['PATH_INFO'] 中以 param1/test1/param2/test2/param3/test3 的形式存放

转换也很容易
PHP code
$s = 'param1/test1/param2/test2/param3/test3';$t = preg_replace('#([^/]+)/([^/]+)/?#', '&$1=$2', $s);parse_str($t, $ar);print_r($ar);<br><font color="#e78608">------解决方案--------------------</font><br>你这个用的是CI?<br><br>$this->uri->segment(n)<br>它允许你重新分割一个详细的URI分段。 n 为你想要得到的段数。分割数按照从左至右的顺序编排。<br><font color="#e78608">------解决方案--------------------</font><br>楼主搞框架啊。我直接explode('/', $url);<br><font color="#e78608">------解决方案--------------------</font><br>$this->uri->segment(n)<br><br>CI是这个方法<br><br>ci是这样处理的:<br>explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string))<br><br><br>  不过我会采用 explode 这个方式了。<div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn