I finally resolved this, thank you all for some good tips (see last paragraph of this post for quick answer).
I was doing a few things wrong that was making things difficult.
I first noticed my encoding problems when records were not getting written to my database, the db and tables were all set to utf-8 so that left the php.
To make things simple I created a test php page to demonstrate the problem. As the page was getting ($_GET) values from the url, when I loaded my test page, I did so with a unicode parameter in the url test.php?sText=Московский
The problem for me, I think, was how IE was interoperating the url, for some reason it couldn't decode its or recognise it as unicode. This became aparrent when I launched the failing page im Chrome, and it worked perfectly.
I proceeded to use the following function to output the full url in Chrome and IE
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
echo curPageURL();
?>
Internet Explorer 8 echoed the following:
http://localhost/FirstProject/test.php?sText=??????????
Chrome however, echoed an encoded url:
http://localhost/FirstProject/test.php?sText=%D0%9C%D0%BE%D1%81%D0%BA%D0%BE%D0%B2%D1%81%D0%BA%D0%B8%D0%B9
As you can see chrome was encoding the url automatically, and PHP was automatically reading and decoding it correctly, presumably because I had set the content type to UTF-8 (thanks Philippe).
I still wasn't sure why IE was behaving like this but it pushed me in the direction to encode the url in the calling page. I was calling the page in javascript so I tried the function encodeURIComponent()
. Thankfully this worked and now im getting the same result in CHROME and IE.
So long story short, if I use encodeURIComponent()
for encoding the calling url an I ensure that I set the content type of the destination php page to header('content-type: text/html; charset=utf-8');
all unicode url variables are processed correctly.
Thanks again for all your help.
Craig