I am using the CodeIgniter framework and I am confused on how to remove %20 from my urls. Below is an example of my code.
Controller – blog
method – show
attribute – this is my blog
public function show($blog= null)
{
// my attempt to set the uri segment
$blogName = $this->uri->segment(3, url_title($blog));
... //other code
}
this doesnt work, I am confused where I implement the url_title(‘this is my blog’) function so that on page load it shows:
/blog/show/this-is-my-blog
do I need to do something in the config/routes.php file?
thank you!
EDIT:
Alright so I found out that url_title() output this20is20my20blog so I now have this:
$blogUrl = str_replace("%20", "-", $blog);
$this->uri->segment(3, $blogUrl);
but it still returns the URL with %20
You just need to use the native php function urldecode to remove any characters that get encoded in a url. Spaces in a URL get encoded to
%20so instead of doing a str_replace just tryhttp://php.net/manual/en/function.urldecode.php