Welcome Guest, Not a member yet? Register   Sign In
How to UTF-8 Encode an URI?
#1

[eluser]developer10[/eluser]
I needed to add some characters to allowed characters whitelist (š,ž,č,ć,đ), but unfortunately these
characters are not properly encoded (by UTF-8) when pulled from URI, so my sql query end up with a strange
black diamond-shaped character with a question mark in the middle of it, in words where normally should any of these
characters be.

For example (word "pričati" - "to talk"):
Code:
... WHERE activity = 'Pri�ati' AND ...

As you can see, all i need is to have these caharacters utf-8 encoded, and my sql query will hopefully be able to retrieve
proper rows.

suggestions?
#2

[eluser]Cro_Crx[/eluser]
I'm not sure if you can have those special characters in a URL and read them correctly, i could be wrong though.

It's not going to be as clean, although you could use urlencode. Although then you would have %something instead of the č character in your URI.

I'm assuming you've set character encoding in your HTML/server headers?
#3

[eluser]developer10[/eluser]
[quote author="Cro_Crx" date="1247428415"]I'm not sure if you can have those special characters in a URL and read them correctly, i could be wrong though.

It's not going to be as clean, although you could use urlencode. Although then you would have %something instead of the č character in your URI.

I'm assuming you've set character encoding in your HTML/server headers?[/quote]

well, i'm not sure about that

since everything else regarding those characters renders well (both static and dynamic content), i think headers are OK

i have this
Code:
header("Content-Type: text/html; charset=UTF-8");

in my view file, and also every file is saved with utf8 encoding (including controller and model) without BOM signature

but, if you think headers should be set/sent in a different way, please post your suggestion, as this seems to be a huge
problem for me.

thanks
#4

[eluser]developer10[/eluser]
FOR DEREK A.

not sure if this is what you asked about, but this is what i have in my config.php for now on allowed characters:

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\šŠćĆčČđĐ-';

EDIT: since i am not getting "disallowed characters in URI" error, after putting those in permitted list, i suppose CI accepts them, but they dont get utf8 encoded so
i end up having wrong parameters in sql (because my characters are being replaced with black diamond-shaped one)
#5

[eluser]Derek Allard[/eluser]
No, what I'm asking is would a url like "http://server.com/šŠćĆčČđ/" be legal. Can you point to any specifications that say it is or isn't. I already know the answer here, but I'm trying to help you out by pointing you in the right direction.
#6

[eluser]developer10[/eluser]
[quote author="Derek Allard" date="1247431848"]No, what I'm asking is would a url like "http://server.com/šŠćĆčČđ/" be legal. Can you point to any specifications that say it is or isn't. I already know the answer here, but I'm trying to help you out by pointing you in the right direction.[/quote]

too bad i fail to see in what direction i should go

i googled on this issue but to no avail. this is how i found your post in your blog. you talk about encoding stuff, but that's
no good for me since i need clear descriptive urls.

so, i hope your answer to my issue is not negative one?
#7

[eluser]developer10[/eluser]
hm, this topic seems to fade away...

and yet, i still did not get the answer. well, derek told me he knows the answer,
so i'm waiting patiently for him to come by and enlighten me. Smile
#8

[eluser]Derek Allard[/eluser]
I'm waiting for you to tell me if those characters are legal to be used in a URL. Smile
#9

[eluser]developer10[/eluser]
[quote author="Derek Allard" date="1247591353"]I'm waiting for you to tell me if those characters are legal to be used in a URL. Smile[/quote]

i need some more clues
i googled many times on this issue and still cant find anything related to THOSE characters being allowed or not in URIs

maybe you didnt mean exploring google results? maybe you thing CI user guide? where's that resource can be found?

and finally, is it possible (tell me that for now, if nothing else).
#10

[eluser]Derek Allard[/eluser]
I'd advise you to not use those characters in your controller names or URL structures. If you need to pass them around, its safest to do so with urlencode.




Theme © iAndrew 2016 - Forum software by © MyBB