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
[email protected]
https://www.mozdev.org/mailman/listinfo/project_owners