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["formSubmit ted"];
if ($formSubmitted ) {
if ($textToTest) {
if (function_exist s("headers_sent ")) {
$sent = headers_sent();
if (!$sent) header("Content-type:text/html;charset=UT F-8");
}
if (function_exist s("recode_strin g")) {
$result = recode_string(" UTF-8", $textToTest);
} else {
echo "<p>functio n 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="testRec ode.php">
<p>type words here:</p>
<textarea name="textToTes t"> Type something here </textarea>
<br><br>
<input type="hidden" name="formSubmi tted" value="true">
<input type="submit">
</form>