2
4

4 に答える 4

1

これは、jQueryのserialize()メソッドの一般的な問題であると考えられます。

解決策を提案する記事がありますが、コメントを必ず読んでください。

http://forum.jquery.com/topic/serialize-problem-with-latin-1-iso-8859-1-and-solution

于 2012-08-20T18:39:26.710 に答える
1

Have you tried parsing the serialized bit in to a string in your PHP before saving it to the database?

parse_str($_POST['field_name'], $php_variable_name);

and use $php_variable_name in your insert query?

Hope this helps :-)

于 2012-08-20T18:20:10.917 に答える
0

JQuery internally uses encodeURIComponent, all data is transferred in UTF-8 anyway. Try again the iconv, but with the UTF-8 converter.

$f = iconv('UTF-8', 'ISO-8859-1', $_POST['f']);

Note that MySql does another conversion for all passed data.

于 2012-08-20T18:29:55.607 に答える
0

Seems that Javascript's encodeURIComponent() encode characters differently than an actual form submition. Ended up re-writing javascript encodeURIComponent function to solve this... Not the most performant solution, but no other solutions presented themselves:

var encodeURIComponent = ( function() {
    var encodeURIComponentOriginal = encodeURIComponent;
    return function ( input ) {
        var toReplace = [
            '%E2%80%9A',
            '%E2%80%A6',
            '%E2%80%98',
            '%E2%80%99',
            '%E2%80%9C',
            '%E2%80%9D',
            '%E2%80%93',
            '%E2%80%94',
            '%E2%84%A2',
            '%C2%A9',
            '%C2%AE',
        ];
        var replaceWith = [
            '%82', // ‚
            '%85', // …
            '%91', // '
            '%92', // '
            '%93', // "
            '%94', // "
            '%96', // –
            '%97', // —
            '%99', // ™
            '%A9', // ©
            '%AE', // ®
        ];               

        var output = encodeURIComponentOriginal( input );

        var length = toReplace.length;

        for ( var i = 0; i < length; i++ ) {
            var regexp = new RegExp( toReplace[i], 'g' );
            output = output.replace( regexp , replaceWith[i] );
        } 

        return output;
    };
} )();
于 2012-08-21T16:07:51.620 に答える