CodeIgniter Forums
Special characters in the URI? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Special characters in the URI? (/showthread.php?tid=13713)



Special characters in the URI? - El Forum - 12-02-2008

[eluser]ryeguy[/eluser]
Is there a way to encode special characters in the URI without enabling them all in the config? I tried using urlencode(), but the percent signs mess everything up and for some reason the server spits out:
Code:
Bad Request
Your browser sent a request that this server could not understand.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

I guess a solution would be to step through the string before it is put in the uri and encode the special characters myself. I could look at each char, see if it is a special character, and if it is, replace it with _asc(character)_. That would be ugly, increase the length of my uri, and it makes me feel dirty. Please don't make me do this. Smile


Special characters in the URI? - El Forum - 12-02-2008

[eluser]JoostV[/eluser]
CI has a function url_title(), in the uri helper that does this for you.
Code:
$dirty_uri = 'This IS %% a ?>:freaky uri';

$this->load->helper('url');
$clean_uri = url_title($dirty_uri);

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html