这个下划线从哪里来?我只能假设魔法 [英] Where is this underscore coming from? I can only assume magic

查看:99
本文介绍了这个下划线从哪里来?我只能假设魔法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在codeigniter框架中有以下测试用例控制器设置:

  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\>点击我< / a>;
}

}

c> $ bla 到echo'foo bar',而不是'foo_bar'。无论如果我使用rawurlencode,urlencode,或根本没有什么,有一个'_'被插入空格字符。我已经确认锚的href包括%20的标志,所以我不明白为什么字符串被改变。



我已经包括两个屏幕截图来说明这一点,第一个图像显示没有传递给控制器​​的参数,第二个是传递给'foo bar'它。我只是不明白为什么'foo%20bar'会被改变?





解决方案

它在PHP 5.3的代码Igniter 2.0完美的,但我猜你的代码段你不使用2.0。



我建议的是尝试查看配置文件。我不能告诉你什么行号不是使用与你相同的版本,但寻找这样

  $ config ['permitted_uri_chars'] ='az 0-9〜%。:_ \-'; 

并确保其中有空格。



可能是在旧版本中,segment函数在传回字符串之前清理了字符串。



这只是一个猜想,但值得一试。 / p>

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?

解决方案

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.

这篇关于这个下划线从哪里来?我只能假设魔法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆