When I discovered this page:
http://us2.php.net/recode_string
I thought this function might solve my problems.
This page says recode_string understands the UTF-8 charset:
http://www.delorie.com/gnu/docs/recode/recode_30.html
I came up with a little test, you can see the code below, and I put it
up on my server:
http://www.publicdomainsoftware.org/testRecode.php
Sadly, my server doesn't seem to have the function recode_string
built-in with PHP. We are leasing a server from Rackspace. I could ask
them to rebuild PHP with that function in it, at a cost of like $120,
but I'd like to know if it would work first.
I wanted to write some very strange characters in a Microsoft Word
document, using every rare and bizzare character I could find, then I'd
copy and paste that to the textarea in the form below, and then I'd see
if it could be output without garbage characters as UTF-8.
But, sadly, I can't run the test on my server. So does anyone know if
this would work?
<?php
$textToTest = $_POST["textToTest"];
$formSubmitted = $_POST["formSubmitted"];
if ($formSubmitted) {
if ($textToTest) {
if (function_exists("headers_sent")) {
$sent = headers_sent();
if (!$sent) header("Content-type:text/html;charset=UTF-8");
}
if (function_exists("recode_string")) {
$result = recode_string("UTF-8", $textToTest);
} else {
echo "<p>function doesn't exist ";
}
echo "<p>here is the resulting text:</p> <p>$result</p> ";
} else {
echo "couldn't find the text ";
}
}
?>
<form method="post" action="testRecode.php">
<p>type words here:</p>
<textarea name="textToTest"> Type something here </textarea>
<br><br>
<input type="hidden" name="formSubmitted" value="true">
<input type="submit">
</form>