473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Decoding UTF-8 data

I am experimenting with CPaint ( http://cpaint.sf.net ) and the data
being returned is in UTF-8 format. The following is supposed to have :
"Slow Driver<br>Very careful".

Slow Driver\u003cbr\u003eVery careful

I can't seem to get rid of the encoded characters. I've tried
unescape(), decodeURIComponent() and decodeURI() to try and get the
data into the format I need with no luck. Data returned by CPaint is
in UTF-8 format by default.

Is there any other function that I can try to use that might help? I
am using Mozilla 1.7.8 on Linux.

Thanks,
Brian

Aug 21 '05 #1
5 2408
On 21/08/2005 22:09, bsnipes wrote:
I am experimenting with CPaint ( http://cpaint.sf.net ) and the data
being returned is in UTF-8 format. The following is supposed to have :
"Slow Driver<br>Very careful".

Slow Driver\u003cbr\u003eVery careful


That isn't UTF-8. \xHHHH is a Unicode escape sequence, where HHHH is a
series of four hexadecimal characters. 0x3c and 0x3e are the codepoint
values of < and > respectively, and when included in a string literal:

'Slow Driver\u003cbr\u003eVery careful'

the interpreter will convert these escape sequences into characters,
just as it would with more recognisable escape sequences, like \n and \t.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 21 '05 #2
The browser isn't showing it as <br>. It shows the unicode chars. Is
there a function I can use to force the translation to the correct
format?

Thanks
Brian

Aug 21 '05 #3
ASM
bsnipes wrote:
The browser isn't showing it as <br>. It shows the unicode chars. Is
there a function I can use to force the translation to the correct
format?


did you try forcing browser in utf-8 mode ?
-> View / Caracteres encode / Unicode UTF-8

you can try with inserting in your html page :
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
in header (between <head> and </head>)

--
Stephane Moriaux et son [moins] vieux Mac
Aug 21 '05 #4
I had that meta tag in the <head> section and it didn't make a
difference. If I view page info in Mozilla, it shows that page as
having ISO-8859-1 encoding and shows the meta tag for UTF-8. Tried
forcing UTF-8 encoding but it didn't make a difference in output. I
just can't put my finger on what is wrong. These are the files in their
entirety (minus the cpaint tarball).

-- testdriver.php ---
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Driver Info</title>
<script src="cpaint2.inc.js" type="text/javascript"></script>
<script type="text/javascript">
var cp = new cpaint();
cp.set_transfer_mode('get');
cp.set_response_type('xml');
// cp.set_debug(true);

function getInfo() {
cp.call("backend.inc.php", 'getDriverInfo', response,
document.getElementById('driver').value);
}

function response(result) {
// use .innerHTML for div tag
// use .value for form elements
document.getElementById('sresult').innerHTML =
result.getElementsByTagName('ajaxResponse').item(0 ).firstChild.data;
document.getElementById('s2result').value =
result.getElementsByTagName('ajaxResponse').item(0 ).firstChild.data;
}
</script>

</head>
<body>
<form>
Choose driver:
<select name="driver" id="driver" onchange="getInfo();">
<option value=""></option>
<option value="Brian">Brian</option>
<option value="Terri">Terri</option>
</select>
</form>
<div name="sresult" id="sresult"></div>
<textarea id="s2result"></textarea>
</body>
</html>
--- end testdriver.php ---
--- backend.inc.php ---
<?php

require_once("cpaint2.inc.php");

$cp = new cpaint();
$cp->register('getDriverInfo');
$cp->start();
$cp->return_data();

function getDriverInfo($name) {
global $cp;
switch ($name) {
case "Brian":
$data = "Slow Driver<br>Very careful ;-)";
break;
case "Terri":
$data = "Fast Driver";
break;
default:
$data = "unknown";
}
$cp->set_id("sdata");
$cp->set_data($data);
return;
}

?>
--- end backend.inc.php ---

Aug 21 '05 #5
Thanks to the cpaint developers, I have my answer. Using
rawurlencode() on the PHP backend.inc.php for the return data and
Javascript's unescape() in the frontend, the data is displayed
properly.

Brian

Aug 23 '05 #6

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

Similar topics

3
by: steve | last post by:
Hi, I am opening a stream that is UTF encoded. I use fgetc to read the stream- which is binary safe. I add every character read to a string. But when I look at the stream, I see some...
1
by: Oliver Kurz | last post by:
Hello, I have a problem by converting a string to base64 and back again. I have a string with german special chars like äöüß. This string i convert with base64str=base64.encode('äöüß') into...
4
by: Chris Curvey | last post by:
I'm writing an XMLRPC server, which is receiving a request (from a non-Python client) that looks like this (formatted for legibility): <?xml version="1.0"?> <methodCall>...
18
by: LarsM | last post by:
Hi all, I am new to XML, but I use it for an RSS feed. I have one problem, which I have really been struggling with. My XML document is generated from the contents of a MySQL database. It is...
9
by: Mark | last post by:
I've run a few simple tests looking at how query string encoding/decoding gets handled in asp.net, and it seems like the situation is even messier than it was in asp... Can't say I think much of the...
5
by: Peter Jansson | last post by:
Hello group, The following code is an attempt to perform URL-decoding of URL-encoded string. Note that std::istringstream is used within the switch, within the loop. Three main issues have been...
6
by: Bill Nguyen | last post by:
Below are sometext I extracted from a mySQL database. How can I decode them so that I can read them in Unicode? Thanks Bill ------------ Virginia Hamilton Adair / Lâm Thị Mỹ...
2
by: pmz | last post by:
Dear Group, I've got a problem with decoding e-mail message subject, which has been read within usage of Pear_Mail_Mime library. There are some elements unwelcome in my subject string, such...
4
by: seedstorm | last post by:
I am using a HtmlInputFile control in ASP.NET 2.0 to upload a file in a UserControl. After upload, I am examining the HttpPostedFile property of this object to read the bytes of the uploaded file's...
8
by: qmpeople | last post by:
Hello, I'm having some problems with decoding urls on IIS6. When I click on URL UTF-8 encoded, resulting querystring replace any non english chars with question marks. Why? I use UTF-8 encoding in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.