Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%20 is added instead of spaces

I guess this is small issue but yet i had to ask here since i am running short in my project. When I pass string to the function in another controller, it changes spaces into %20 sign. I guess the controller thinks the string passed as url and encodes it. But I don't know exactly how to remove it or if possible do not let it to change spaces into %20. Here is the code which i use;

$message="The user name you provided is already in our database";
redirect('admin/add_user/'.$message);

Here is my controller function where i receive the message;

public function add_user($message)
{
  echo $message;
}

I also tried this as;

public function add_user()
{
  echo $this->uri->segment(3);
}

But the result is same. Here is the output of the string;

The%20user%20name%20you%20provided%20is%20already%20in%20our%20database
like image 416
Afghan Host Avatar asked Mar 18 '13 11:03

Afghan Host


2 Answers

Try this:

public function add_user($message)
{
  echo urldecode($message);
}

You can read more about urldecode here: http://php.net/manual/en/function.urldecode.php

like image 178
Fabio Antunes Avatar answered Oct 12 '22 21:10

Fabio Antunes


Try this:

echo urldecode($message);

because you are passing the message as part of the URL (The redirect does a new http request) it is automatically url encoded. You just need to decode it once the server receives it.

like image 28
cowls Avatar answered Oct 12 '22 23:10

cowls