Forum Moderators: coopster

Message Too Old, No Replies

working with UNICODE

Management of Special Chars in string for PHP and JavaScript

         

pcwow

8:15 pm on May 11, 2009 (gmt 0)

10+ Year Member



when writing text inside html it would be like
código, therefore "ó" would be shown...

Now I'm trying to do the same inside a alert() function
what am I sopposed to do?
tried:
txt = "digite a c" += \u00F3 += "digo da imagem!";
atlert(txt)
if fails, object expected...

how can I show an alert message using symbols from another language (portugese) to be more specific...

in English
alert("you didn't type the image code...")

in Portuguse
alert("você não digitou o código da imagem...")

how will I add the symbols: ê, ã, ó into my message?

Help is always appreciated! ;)

eelixduppy

9:11 pm on May 12, 2009 (gmt 0)



You could do something like this:


alert("<?php echo [url=http://www.php.net/html-entity-decode]html_entity_decode[/url]($string); ?>");

Where

$string
contains the Portuguese text. Also, make sure that the string is properly escaped when it comes to quotes.

pcwow

2:39 am on May 13, 2009 (gmt 0)

10+ Year Member



I still don't get it...
can yo show me the exemple above in the code for PHP and JS?

"você não digitou o código da imagem..." How do I do the code for this output...

eelixduppy

3:27 am on May 14, 2009 (gmt 0)



I'm assuming you are retrieving the text from somewhere, correct? Which way it it written where you are getting it? There are two ways you've given me...

1) c&oacute;digo
2) código

If you have the html entity one you need to decode them before you echo it into an alert() otherwise it will not work. Otherwise echoing it should do just fine.

In my example above if you set...


$string = 'c&oacute;digo';

...you will see that I'm talking about.