%20 is added instead of spaces

Afghan Host picture Afghan Host · Mar 18, 2013 · Viewed 11.1k times · Source

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

Answer

Fabio Antunes picture Fabio Antunes · Mar 18, 2013

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