为什么echo $ this-> uri-> segment(3)输出与我在url中看到的不同

时间:2013-04-17 13:17:56

标签: php codeigniter

所以我有这样的网址:

http://localhost/testproject/data/getData/幻想

然后在函数getData中我有:

public function getData($title){
    echo $title;
}

在输出中我看到:

%E5%B9%BB%E6%83%B3

同样如果我尝试$ this-> uri-> segment(3)。 为什么会这样,以及如何解决它?我也注意到,如果我在这里粘贴整个网址,我会得到:

  http://localhost/testproject/data/getData/%E5%B9%BB%E6%83%B3

我真的死在这里...

顺便说一下。文件以UTF8编码。

3 个答案:

答案 0 :(得分:1)

Use this

site_url('data/getData/'.urlencode('幻想'));

在php结束时使用此

$segment = $this->uri->segment(3);
$value = urldecode($segment);

看看这是否适合你。

答案 1 :(得分:1)

您可以使用urldecode查看此http://php.net/manual/fr/function.urldecode.php

答案 2 :(得分:0)

因空间字符,空格。

尝试对您的网址进行编码或解码以查看正确的用户urldecode()函数或urlencode()取决于您要显示的方式...

http://www.php.net/manual/en/function.urlencode.php

http://php.net/manual/en/function.urldecode.php