I’m trying to replace a URL in CodeIgniter that has certain parameters. Not that CI should matter at this point as I have the best part of it working.
Lets say my URL is :
?device=field1-field2_field3+field4
By echoing out $devicelink2 that should show:
field1 field2.field3*field4
Currently it works with everything but replacing the +. For some reason it replaces + with a space.
However I can’t get that working using the below code. Any ideas?
$device = $this->input->get('device');
$devicelink = str_replace("-"," ",$device);
$devicelink1 = str_replace("_",".",$devicelink);
$devicelink2 = str_replace("+","*",$devicelink1);
+in a query string actually represents a space character, so with this (very odd) query string:$this->input->get('device')is equal tofield1-field2_field3 field4To answer your literal question of how to get your desired output with this exact query string:
Or:
If you are having trouble just getting these characters into the original query string, just make sure to encode it properly:
See PHP’s native
urlencodefunction for help with this: http://php.net/manual/en/function.urlencode.php