请教【框架爱好者们】地址栏参数的简易获取方式。
<!--
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);
?>
$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>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号