This is a discussion on can recode_string auto-convert to UTF-8? within the PHP Language forums, part of the PHP Programming Forums category; When I discovered this page: http://us2.php.net/recode_string I thought this function might solve my problems. This page ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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> |
|
|||
|
On 27 May 2005 13:08:32 -0700, lkrubner@geocities.com wrote:
>When I discovered this page: > >http://us2.php.net/recode_string > >I thought this function might solve my problems. Which problem? >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. Remember the Joel article you posted? It's all down to the key sentence in there; if you don't know the original encoding of your data you are stuffed. >But, sadly, I can't run the test on my server. So does anyone know if >this would work? > > if (function_exists("recode_string")) { > $result = recode_string("UTF-8", $textToTest); recode_string converts from one encoding to another. You've specified just one encoding. What's it supposed to do? From a brief read of the manual it seems to default to Latin-1 a.k.a ISO-8859-1 if you don't specify one of the encodings. If it's not in ISO-8859-1 in the first place, the results won't be "correct". This function doesn't seem any different, as far as I can see, to http://uk.php.net/manual/en/function...t-encoding.php except it's more obscure. -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |