问题
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
回答1:
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
回答2:
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.
回答3:
When saving to the database use:
htmlentities($variable)
when outputing use:
echo html_entity_decode($variable, ENT_COMPAT, 'UTF-8');
来源:https://stackoverflow.com/questions/15475645/20-is-added-instead-of-spaces