<?php header("Content-type: text/html; charset=UTF-8"); ?>(Or equivalent for their language) and
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
for their output and for MySQL use UTF8_general_ci Collation. For the most part, if you work with those steps you will make it out alive without a headache either.
Last night, I encountered an issue that just boggled me for hours. I'm using JQuery to not only spiffy up the content but submit form data inline like Facebook & Twitter had made famous to the general population. All was well until the inevitable occurred, the client posted content he wrote in MS Word. No problem normally, but this time it kept going into the MySQl table garbled. At first I figured I needed to decode the output but that wasn't it... the special characters where changed into "ã" which still doesn't make since to me. I stabbed at the problem for about 3 hours before I came to the conclusion finally that the data I was receiving from the form was garbage before PHP got hold of it. Tinkering around, I ran the input's value through encodeURI() and decoded the POST data and viola! Here is an sample of what I did:
JQuery
$save.click(function(){
$.post('saveText.php',{ text : encodeURI($text.val()) } );
});saveText.php
...
$text = urldecode($_POST['text']);
...
0 comments:
Post a Comment