Page 1 of 1

building javascript strings with shift-js charset

Posted: Tue Aug 10, 2004 4:43 am
by giorgio
I need to build a Javascript array on values I read in my database. My code is like this:

<SCRIPT>
var key = [];

<?

## $lang is the user system language or his preferred language

$sql = "SELECT keyName,".$lang." FROM localization";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "key['".$row["keyName"]."'] = '".addslashes($row[$lang])."';";
}

?>
</SCRIPT>


Do you see anything strange? I don't.
And actually this code works perfectly either with european database entries (whatever is the current charset) or with japanese entries (provided that the currect charset is wrong so that you see the stupid ansi string).
When the charset is the right one (shift-jis) and the lang is japanese something very strange happens: the closing quote is encoded together with the text, and the result is obviously an "unterminated string" error.

I've gone crazy looking for some tips on this problem that should be a stupid problem (as js and php are used in Japan as well, right?), but my conclusion is that possible tips are only in japanese.

Can somebody help me?