DBCS not saving properly
I have an edit.php file which will allow me to edit the contents of a web form. All the text is stored in .txt files. The problem comes when I try to enter characters in Japanese, or Korean etc.
I will input this: "たんじょびおめでとう"
and once I save it, it returns this: "%u305F%u3093%u3058%u3087%u3073%u304A%u3081%u3067%u3068%u3046"
Does any one have any ideas as to how to have the characters saved correctly. I find if I change the encoding on the .txt files to UTF-8 and input the characters using notepad rather then through edit.php it开发者_运维问答 tends to save fine, though I'd rather not have to do this.
Thanks for your help!
EDIT
I wasn't sure what code to put, but I'm assuming it's to do with my way of saving. Here is my save.php file:$content = $_POST['content'];
if($content == ''){
echo "You cannot null this field, please reload the page.";
} else {
echo $content;
$myFile = "text/".$_POST['id'].".txt";
$fh = fopen($myFile, 'w') or die("Could not update");
fwrite($fh,$content);
fclose($fh);
}
You'll need to check which character encoding you're inputing with (probably ISO 8859-1 or CP 1252 on Windows).
In any case, transforming your returned string into the desired output encoding should be easy, as your string:
%u305F%u3093%u3058%u3087%u3073%u304A%u3081%u3067%u3068%u3046
Are the 10 Unicode escape sequences (UTF-8) for the Japanese you have entered ("Happy Birthday"). When you input them directly into a text file, I'm assuming the application is setting the encoding correctly.
If it's for a web form, check what the encoding is set to in the request header, for example:
Content-Type text/xml;charset=utf-8
精彩评论