2

I need to do some string operations on $_SERVER value especially $_SERVER['REQUEST_URI']

How PHP encodes such strings? Should I use mb_* family functions?

To understand better my question, let's say I have a page on my webserver called like this:

ããã.php

And I need to get the second char:

echo mb_substr($_SERVER['REQUEST_URI'],1,1);

2 Answers2

4

How PHP encodes such strings?

PHP won't do anything to the string, but the web browser will usually percent encode any non-ASCII characters in REQUEST_URI. (I say "usually" because I have seen IE not do it. I expect, however, Apache to do the job in that case - but I'm not entirely sure whether it will. You'd have to try out.)

Running urldecode() will decode those characters.

Related reading: Unicode characters in URLs

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

$_SERVER['REQUEST_URI'] usually doesn't contain stuff which would require usage of Multibyte functions so I guess if you don't tend to do unusual stuff with the request URIs such as stuffing them with non-ASCII characters (caused by weird URI rewrites etc.) you are safe to use the "normal" PHP string manipulation functions.

  • @yes `ããã.html` is not a valid URL - the special characters will be percent encoded. see [Unicode characters in URLs](http://stackoverflow.com/q/2742852) – Pekka Dec 19 '11 at 18:20