douyong1905 2011-04-05 07:03
浏览 12
已采纳

这个下划线来自哪里? 我只能假装魔法

I have the following test case controller setup in a codeigniter framework:

class Test extends Controller {
    public function Test()
    {
        parent::Controller();
    }

    public function index($bla = ''){
        echo $this->uri->segment(3) . '<br/>';
        echo $bla . '<br/>';

        $url = site_url('test') . '/index/' . rawurlencode('foo bar') . '/';

        echo "<a href=\"$url\">click me</a>";
    }

}

I would like $bla to echo 'foo bar', not 'foo_bar'. Regardless if I use rawurlencode, urlencode, or nothing at all, there is a '_' being inserted for the space character. I have confirmed the href for the anchor does include the %20 sign, so I don't understand why the string is being altered.

I have included two screen shots to illustrate the point, the first image shows when no argument is passed to the controller, the second is with the 'foo bar' passed to it. I just don't understand why 'foo%20bar' would be altered?

enter image description here

enter image description here

  • 写回答

4条回答 默认 最新

  • dongtigai3875 2011-04-05 12:53
    关注

    It works perfectly in Code Igniter 2.0 on PHP 5.3, but i'm guessing by your snippet that you're not using 2.0.

    What I would suggest is try looking in the config file. I can't tell you what line number it is not using the same version as you but look for something like this

    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
    

    And making sure there's a space in it.

    It may be that in older versions the segment function cleaned up the string before passing it back.

    This is only a guess mind, but worth a shot.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址