问题描述:

I have one method in controller that receive several parameters:

public function api(){

$url_params = $this->uri->segment_array();

//...

}

and this is example of 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"

}

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

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

How to get real value

网友答案:

Use urldecode() to decode string

...
 $url_params = $this->uri->segment_array();
 foreach($url_params as &$param) {
   $param = urldecode($param);
 }
 ...
网友答案:

You can try urldecode.

echo urldecode("some%20message");

This will return "some message"

网友答案:

Use urldecode() to Decode URL-encoded string

相关阅读:
Top