473,503 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>

Jul 17 '05 #1
2 2873
On 27 May 2005 13:08:32 -0700, lk******@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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
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"

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2588
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
1
13941
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
5
6080
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
2833
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
5050
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
5030
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
3247
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
22
3034
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
3047
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
6302
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.