如何在Codeigniter中将带有空格的参数从URL传递到控制器? [英] How to pass parameters with space to controller from URL in codeigniter?

查看:76
本文介绍了如何在Codeigniter中将带有空格的参数从URL传递到控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制器中有一个方法可以接收几个参数:

I have one method in controller that receive several parameters:

public function api(){
  $url_params = $this->uri->segment_array();

   //...
}

这是URL示例:

http://testsite.com/services/api/invite-businesses/contact_name/_testing/message/some%20message/url/some_URL/

所以我的数组看起来像:

So my array seems like:

array(10) {
  [1]=>
  string(8) "services"
  [2]=>
  string(3) "api"
  [3]=>
  string(17) "invite-businesses"
  [4]=>
  string(12) "contact_name"
  [5]=>
  string(12) "_testing"
  [6]=>
  string(7) "message"
  [7]=>
  string(14) "some%20message"
  [8]=>
  string(3) "url"
  [9]=>
  string(4) "some_URL"
}

您可以看到一个的参数有空格: some%20message

You can see that one of parameters has space: some%20message.

但是我想获取实际价值,ae 一些消息。该值可能包含URL转换为%xx 的任何其他字符。

But I want to get real value, a.e. some message. The value might contain any other character that URL converts to %xx.

如何获得实际价值

推荐答案

使用 urldecode() 以解码字符串

Use urldecode() to decode string

...
 $url_params = $this->uri->segment_array();
 foreach($url_params as &$param) {
   $param = urldecode($param);
 }
 ...

这篇关于如何在Codeigniter中将带有空格的参数从URL传递到控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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