can recode_string auto-convert to UTF-8?

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-27-2005
lkrubner@geocities.com
 
Posts: n/a
Default can recode_string auto-convert to UTF-8?






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>

Reply With Quote
  #2 (permalink)  
Old 05-27-2005
Andy Hassall
 
Posts: n/a
Default Re: can recode_string auto-convert to UTF-8?

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
Reply With Quote
  #3 (permalink)  
Old 05-28-2005
lkrubner@geocities.com
 
Posts: n/a
Default Re: can recode_string auto-convert to UTF-8?

My apologies. I didn't read it well enough. As you say, "if you don't
know the original encoding of your data you are stuffed"

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:52 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0