CodeIgniter Forums
URL encoding problems... - 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: URL encoding problems... (/showthread.php?tid=40092)



URL encoding problems... - El Forum - 03-30-2011

[eluser]Rob Corley[/eluser]
Hello,

Apologies first if I am posting in the wrong place!

I am trying to pass a filename in the URL, so I am using urlencode to encode something like this:-

http://www.example.com/page/file name.ext/some folder name/

I then want to use the strings ‘file name.ext’ and ‘some folder name’ in the page controller. However codeigniter when I retrieve the URL string returns it with the . and the spaces as underscores:-

‘files_name_ext’

So I have no way to differentiate between the 2. (some filenames contain multiple dots so I can’t just replace the 4th last character).

Many thanks in advance!


URL encoding problems... - El Forum - 03-30-2011

[eluser]John_Betong_002[/eluser]
Take a look at the User Guide for the URI Class

http://ellislab.com/codeigniter/user-guide/libraries/uri.html

Code:
// Your code where the URL is decoded

// Beware: my code not tried or tested :)
echo '<br />',
  $filename = $this->uri->uri_string();

echo '<br />',
  str_replace('_', '.', $filename);

die;
&nbsp;
&nbsp;
&nbsp;


URL encoding problems... - El Forum - 03-30-2011

[eluser]danmontgomery[/eluser]
This is PHP functionality, not Codeigniter. See http://us.php.net/variables.external:

Quote:Dots and spaces in variable names are converted to underscores. For example &lt;input name="a.b" /&gt; becomes $_REQUEST["a_b"].

There have been workarounds posted here before, the first one I came up with is: http://ellislab.com/forums/viewthread/94091/