473,387 Members | 1,891 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,387 software developers and data experts.

html_entity_decode and unicode cyrillic characters

Hi

I have a string such as

Добро"

that shows the cyrillic word "?????" in the browser. Now I played around
with lots of examples and contributed functions in the manual
(html_entity_decode, strtr, convert_cyr_string ...) but was not able to
decode these entities. As browsers displays them correctly on my PC and Mac
I think I am missing something...

Somebody can point me to the right direction?

(The problem is: A user posts russian text in an application. The text
arrives at the server encoded like that. Now for security reasons the output
is converted with htmlentities(). So I have to decode the russian entities
before re-encoding them.)

Thanks
Markus
Jul 17 '05 #1
10 7664
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
I have a string such as

Добро"

that shows the cyrillic word "?????" in the browser. Now I played around
with lots of examples and contributed functions in the manual
(html_entity_decode, strtr, convert_cyr_string ...) but was not able to
decode these entities. As browsers displays them correctly on my PC and Mac
I think I am missing something...
Decode them into what?
(The problem is: A user posts russian text in an application. The text
arrives at the server encoded like that. Now for security reasons the output
is converted with htmlentities(). So I have to decode the russian entities
before re-encoding them.)


So don't use htmlentities (I can't imagine any use of it anyway), use
htmlspecialchars instead.

Jul 17 '05 #2
Daniel Tryba wrote:
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
I have a string such as

Добро"

that shows the cyrillic word "?????" in the browser. Now I played
around with lots of examples and contributed functions in the manual
(html_entity_decode, strtr, convert_cyr_string ...) but was not able
to decode these entities. As browsers displays them correctly on my
PC and Mac I think I am missing something...


Decode them into what?


Into anything that does not contain an ampersand or other special character,
and can be properly displayed or decoded for display.
(The problem is: A user posts russian text in an application. The
text arrives at the server encoded like that. Now for security
reasons the output is converted with htmlentities(). So I have to
decode the russian entities before re-encoding them.)


So don't use htmlentities (I can't imagine any use of it anyway), use
htmlspecialchars instead.


That does not make any difference, as both convert Д into
&amp;#1044; - which is exactly the problem.

--
Markus
Jul 17 '05 #3
Markus Ernst wrote:
I have a string such as

Добро"

that shows the cyrillic word "?????" in the browser. Now I played around with lots of examples and contributed functions in the manual
(html_entity_decode, strtr, convert_cyr_string ...) but was not able to decode these entities. As browsers displays them correctly on my PC and Mac I think I am missing something...

Somebody can point me to the right direction?


http://in2.php.net/utf8_encode#49336

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #4
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
I have a string such as

Добро"

Decode them into what?


Into anything that does not contain an ampersand or other special character,
and can be properly displayed or decoded for display.


Ahhh, so why have them encoded in the first place, you know that you can
specify in what character encoding browsers are supposed do send the
characters (see w3)!

So attack your problem at the source:
use a decend encoding (either the proper iso8859-x for
cyrillic, or better yet UTF-8 so you can "mix chactersets").
So don't use htmlentities (I can't imagine any use of it anyway), use
htmlspecialchars instead.


That does not make any difference, as both convert Д into
&amp;#1044; - which is exactly the problem.


Doh! :)

Jul 17 '05 #5
Daniel Tryba wrote:

Ahhh, so why have them encoded in the first place, you know that you
can specify in what character encoding browsers are supposed do send
the characters (see w3)!

So attack your problem at the source:
use a decend encoding (either the proper iso8859-x for
cyrillic, or better yet UTF-8 so you can "mix chactersets").


Thank you, this is definitely the way to go. Anyway, <meta
http-equiv="content-type" content="text/html;charset=utf-8"> does not make
IE use UTF-8. But when manually settin UTF-8, the characters are actually
transferred unencoded.

For a quick and dirty fix, this did the trick for proper display:
$text = preg_replace("/&amp;#([0-9a-fx]+);/mi", "&#\$1;", $text);

But I will definitely try to go the Unicode way.

--
Markus
Jul 17 '05 #6
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
So attack your problem at the source:
use a decend encoding (either the proper iso8859-x for
cyrillic, or better yet UTF-8 so you can "mix chactersets").
Thank you, this is definitely the way to go. Anyway, <meta
http-equiv="content-type" content="text/html;charset=utf-8"> does not make
IE use UTF-8. But when manually settin UTF-8, the characters are actually
transferred unencoded.


When using PHP please don't use those silly http-equiv thingies, use the
real headers instead: header('Content-Type: text/html; charset=UTF-8');

You also might want to add the correct attribute to the form element
(IIRC accept-encoding, but see w3c to be sure).
For a quick and dirty fix, this did the trick for proper display:
$text = preg_replace("/&amp;#([0-9a-fx]+);/mi", "&#\$1;", $text);
Nice one, I was wondering if using chr() worked, but this is much nicer
(although still a hack :)
But I will definitely try to go the Unicode way.


_The_ way to go. Take a look at the MultiByte String section of the
manual, setting output and internal encoding to UTF-8 works for me (I
never heard any complaints so far).

Jul 17 '05 #7
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:42**********@news.cybercity.ch...
For a quick and dirty fix, this did the trick for proper display:
$text = preg_replace("/&amp;#([0-9a-fx]+);/mi", "&#\$1;", $text);
The &$xxxx; format accepts decimal, so the a-f part is unnecessary :-)
But I will definitely try to go the Unicode way.


Switching from a single byte charset to a multibyte encoding is a fairly big
change. At the least you're looking at transcoding all your existing data.
Jul 17 '05 #8
Chung Leong wrote:
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:42**********@news.cybercity.ch...
For a quick and dirty fix, this did the trick for proper display:
$text = preg_replace("/&amp;#([0-9a-fx]+);/mi", "&#\$1;", $text);


The &$xxxx; format accepts decimal, so the a-f part is unnecessary :-)
But I will definitely try to go the Unicode way.


Switching from a single byte charset to a multibyte encoding is a
fairly big change. At the least you're looking at transcoding all
your existing data.


Thank you for this input - I will work on fixing that whole thing before the
application goes productive and the users begin to submit real text.

--
Markus
Jul 17 '05 #9
Daniel Tryba wrote:

When using PHP please don't use those silly http-equiv thingies, use
the real headers instead: header('Content-Type: text/html;
charset=UTF-8');
Oh - I was proud of having created an application where the proper encoding
for the selected language was automatically used in the http-equiv thingy...
But I admit that from the beginning I was afraid of the moment somebody
decided to make an arab or hebrew or thai web site with it :-) I am working
on a CMS system that can handle an unlimited number of language versions for
every page of the site, but did not think of the possibility of mixing up
languages inside of a page. I am actually lucky that a user of a previous
version of the system tried to do exactly this :-)
You also might want to add the correct attribute to the form element
(IIRC accept-encoding, but see w3c to be sure).


I thought I knew really a lot about HTML, but there are still lots of things
to learn (it is accept-charset).
For a quick and dirty fix, this did the trick for proper display:
$text = preg_replace("/&amp;#([0-9a-fx]+);/mi", "&#\$1;", $text);


Nice one, I was wondering if using chr() worked, but this is much
nicer (although still a hack :)


I tried all examples with chr() I found in the manual, and it was
interesting how different the results can be with different operations
performed before or after. There must be conflicts between different
encodings of cyrillic and I doubt that a solution found for those characters
I get would reliably work for cyrillic characters sent from any other
system.
But I will definitely try to go the Unicode way.


_The_ way to go. Take a look at the MultiByte String section of the
manual, setting output and internal encoding to UTF-8 works for me (I
never heard any complaints so far).


I will spend more time on learning about that. Thanks a lot for your inputs.

--
Markus
Jul 17 '05 #10
R. Rajesh Jeba Anbiah wrote:
Somebody can point me to the right direction?


http://in2.php.net/utf8_encode#49336


Thank you, this works well! I even had come across it before, but as I was
not aware of the UTF-8 header stuff I (and thus got bad results) had not
given it much attention.

--
Markus
Jul 17 '05 #11

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

Similar topics

1
by: Avnish | last post by:
Hi, I am looking for some form of validation for all the alphanumeric characters in the entire unicode range e.g. the validation should also accept japanese characters but should restrict...
0
by: Dmitry Krivov | last post by:
Hi, Sorry for my english, my native is russian I have an Oracle-nickname in DB2 UDB 7.2 database, but when i'm trying to select fields an returning result set contain ???? instead of cyrillic...
3
by: Sakcee | last post by:
Hi In one of the data files that I have , I am seeing these characters \xed\xa0\xa0 . They seem to break the xsl. --------------------------------------------------------------- Extra...
5
by: snapcount | last post by:
When I enter Cyrillic characters into MySQL, it gets converted to ш or something. How do I disable this and is there any workaround? Thanks
3
by: Bruce | last post by:
The ComboBox has a context menu with an option to "Show Unicode Control Characters". How can I use that context menu in a RichTextBox or call that functionality from a RichTextBox? Is there a way...
4
by: phasma | last post by:
Hi, I'm trying extract all alphabetic characters from string. reg = re.compile('(?u)(+)', re.UNICODE) buf = re.match(string) But it's doesn't work. If string starts from Cyrillic character,...
2
by: KK | last post by:
Hello all, There could be flavors of this question discussed in the past, but I could not really make a head/tail out of it. I have bunch of unicode values stored in a string array and I want to...
6
by: Shiao | last post by:
Hello, I'm trying to build a regex in python to identify punctuation characters in all the languages. Some regex implementations support an extended syntax \p{P} that does just that. As far as I...
0
by: Jams Quiden | last post by:
I have a ESRI personal geodb with Cyrillic, chinese and arabic characters that will not, no matter what client encoding I choose, transfer nicely to PostGIS db. I am using ogr2ogr tools. I am on a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.