I am using Wampserver for my Windows Apache-PHP-MySQL stack. The file accessed has a header that defines it as utf-8, meta tag in HTML also defines it as utf-8.

My best guess so far is that it has something to do with Apache. Searching through Google was of little help thanks to rather common keywords used. When I enter:

[protocol]://localhost/originnode/?test=õäöü

.. the browser converts the URL to ..

[protocol]://localhost/originnode/?test=%F5%E4%F6%FC

.. and same applies to $_GET string returned to the document. Now I know that a hosting service I am using has no such problem, the same file functions as expected on one of the virtualhosts I am renting. This only happens on localhost.

Any solution to this problem? Where to look?

One of the threads I found from Google mentioned the value 'AddDefaultCharset', which is not defined in my install. Language configuration does have AddCharsets (which does include utf-8) as well as languages, but that value was not defined. When I defined it myself as "AddDefaultCharset utf-8" in the end and restarted, nothing changed and the URL was still convered.

Any help would be appreciated, thanks!

Take a look here: http://nl3.php.net/manual/en/ref.url.php. It is all about url's.

Thanks, but could you be more specific? That makes it sound like it's something I need to add to the script that is executed. However the thing is that the same code works on the installation server without requiring any additions. I suppose I need to do some additional trial&error testing then.

EDIT: I found that the URL will be correct, if it is submitted with a method="get" form, but will be converted incorrect when accessed straight from URL.

To be more specific, your installation server is probably running Linux. UTF-8 and Linux are more or less friends. Most of the time no problems. But your local system runs on Windows. And Windows can handle UTF-8 but always with a lot of problems. To solve it insert this

function url_encode($string){
        return urlencode(utf8_encode($string));
    }
   
    function url_decode($string){
        return utf8_decode(urldecode($string));
    }

in your php file(s) on the local machine and use these to get the right url. When you upload it to your installation server change the functions like so:

function url_encode($string){
        // return urlencode(utf8_encode($string));
        return $string;
    }
   
    function url_decode($string){
        // return utf8_decode(urldecode($string));
       return $string;
    }

You could also insert some code to test if the php file is executed on a Windows machine and do the encode or decode only if so.

commented: Very helpful +0
commented: Good point. +6

Much appreciated, I feared that the difference might be because of Linux-Windows. I might have to go with an automatic detection for this, to keep the thing multi-platform.

Much appreciated, I feared that the difference might be because of Linux-Windows. I might have to go with an automatic detection for this, to keep the thing multi-platform.

You can test for a Windows environment this way:

function url_encode($string){
     if (strtoupper(substr(PHP_OS,0,3)=='WIN')) $string =  urlencode(utf8_encode($string));
     return $string;
}
   
function url_decode($string){
     if (strtoupper(substr(PHP_OS,0,3)=='WIN')) $string = utf8_decode(urldecode($string));
     return $string;
}

If it runs on Windows the string will be converted, if not it will simply return as it is.

Online02 will you please read the rules before posting!!

Online02 will you please read the rules before posting!!

Online02 has been warned. Please report spammers to keep Daniweb clean :) Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.