[Project_owners] Unicode encoding (Hebrew, sinhala etc) using JAVASCRIPT & decoding using PHP

Silver Surfer silver.surfer444 at gmail.com
Sun Oct 26 22:41:58 PDT 2008


Hi Roberto,
Thanks for your help. I did as you said and alert the sent text. Then it
shows the hebrew strings without any modification. But it didn't go to the
database until I put these lines before execute the mysql insert query.

mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
mysql_query("SET character_set_database=utf8");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_server=utf8");


Then It works nicely. But I thought only neccessity for inserting UNICODE
string to a database is create it in utf8_coalition .
Anyway problem solved.
Thanks & regards,
Manjula

On Mon, Oct 27, 2008 at 10:53 AM, Roberto Bouzout (tito) <zilla at nxuy.com>wrote:

>  I need to know how can I send an unicode text like Hebrew through
>> JAVASCRIPT (encode) and get it from PHP (decode it) to save it to a
>> MySQL database.
>>
>
> I do this:
>
>        var url = 'http://www.domain.com/some/file?decoded='+X_EncodeUTF8('
> מחשבים');
>        var browser = window.getBrowser();
>        var tab = browser.addTab(url);
>
> function X_EncodeUTF8(string)
> {
>        try
>        {
>                return encodeURIComponent(string);
>        }
>        catch(err)
>        {
>                try
>                {
>                        return encodeURI(string);
>                }
>                catch(err)
>                {
>                        return (string);
>                }
>        }
> }
>
> PHP:
> echo $_GET['decoded'];
>
> /*
>
> will print 'מחשבים'
> Assuming that your server 'serve' the file as UTF-8 ( see: "text/html;
> charset=UTF-"8 at the response   headers)
>
> */
>
> I do the try and catch in the X_EncodeUTF8 because sometimes the argument
> maybe is malformed.. but valid.
>
> alert(decodeURI('http://example.net/canci%f3n/'))
>
> Error: URIError: malformed URI sequence
> Source file: Javascript Command
> Line: 1
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> https://www.mozdev.org/mailman/listinfo/project_owners
>



-- 
~Silver Surfer~
Surfing through time & space
http://risingofsilversurfer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mozdev.org/pipermail/project_owners/attachments/20081027/88fadbc1/attachment.html>


More information about the Project_owners mailing list