• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-24) 27次浏览 已收录 0个评论

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

PHP code

<!---ecms 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="prettyprint linenums">";    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);
------解决方案--------------------
你这个用的是CI?

$this->uri->segment(n)
它允许你重新分割一个详细的URI分段。 n 为你想要得到的段数。分割数按照从左至右的顺序编排。
------解决方案--------------------
楼主搞框架啊。我直接explode('/', $url);
------解决方案--------------------
$this->uri->segment(n)

CI是这个方法

ci是这样处理的:
explode("/", preg_replace("|/*本%文来源gaodaimacom搞#^代%!码网@搞代gaodaima码(.+?)/*$|", "\\1", $this->uri_string))

不过我会采用 explode 这个方式了。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:请问【框架爱好者们】地址栏参数的简易获取方式

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址