I am currently tying myself up in knots over URL percent-encoding of extended Latin characters.
Step 1 of 4
I have the following URL:
The offline folder name (which I have uploaded via FTP) exactly corresponds to this:
Step 2 of 4
Wherever this URL has an internal link pointing to it anywhere on the site, the link now takes the percent-encoded form:
If I cut and paste the URL from the URL bar in Firefox, it pastes as:
Step 3 of 4
But... imagine that URL is a referrer to the current page.
If I now use PHP to grab the URL (and edit it a little):
$My_Reference = str_replace('https://'.$_SERVER['HTTP_HOST'], '', $_SERVER['HTTP_REFERER']); $My_Reference = explode('?', $My_Reference); $My_Reference = substr($My_Reference, 1, -1);
and then later, I use
$My_Reference to retrieve some related data:
it doesn't work.
I had a think about this and concluded that this might be what's happening:
file_get_contents()is (somehow?) detecting the extended Latin characters in
fu%C3%9Fg%C3%A4ngerbr%C3%BCcke. (Can this be right?)
- It then looks for a folder which literally exists as
/fu%C3%9Fg%C3%A4ngerbr%C3%BCcke/and can't find it, because the only folder that exists is
So, to test this hypothesis, I tried:
which does work (hooray!), but... well, it seems weird.
I felt uncomfortable about this, since I'm not trying (and don't need) to decode percent-encoded URLs anywhere else on the site, in any other context, and this just makes for a weird exception. For the sake of consistency, I'd just rather use percent-encoding everywhere.
Step 4 of 4
So... I went back to the original offline folder and renamed it from
and then uploaded it and replaced the old folder.
Guess what...? The new URL doesn't resolve!
Instead, I get a
Presumably because the server is now automatically decoding the hardcoded percent-encoding and trying to find the folder
/fußgängerbrücke/ in the webspace... which isn't there.
If I upload a folder named
Whereas if I upload a folder named
/fußgängerbrückegoes to a
/fu%C3%9Fg%C3%A4ngerbr%C3%BCckegoes to a
So what am I missing here? Two questions:
file_get_contents()automatically percent-encode extended Latin characters which then need to be explicitly percent-decoded again?
- Is it impossible to have URL foldernames and filenames which have percent-encoding already hardcoded into them?