CKEditor没有保存在utf-8中

时间:2017-03-07 10:39:31

标签: php html mysql utf-8 ckeditor

我会尽快理解它。我的PHP项目出了问题我无法解决它,我的网站上有一个CKEditor实例。

这是配置和实例:

    <script src="assets/ckeditor/ckeditor.js" charset="UTF-8"></script>

<textarea class="ckeditor" name="editor1" id="editor" rows="10" cols="80" required value="<?php if($error) echo $profdesc; ?> ">
            <?php echo $profdesc; ?>
    </textarea>

    <script>
      CKEDITOR.replace('editor1', {
        contentsCss: "assets/ckeditor/test.css",
        uiColor: '#428bca',
        extraPlugins: 'wordcount,lineheight,colorbutton,smiley',
                    wordcount: {
                        showWordCount: true,
                      showParagraphs: false,
                      showCharCount: true,
                        maxCharCount: 3000,
                        paragraphsCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationparagraphs").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - paragraphs").show();
                        },
                        wordCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationword").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - word").show();
                        },
                        charCountGreaterThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationchar").css("background-color", "crimson").css("color", "white").text(currentLength + "/" + maxLength + " - char").show();
                        },
                        charCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationchar").css("background-color", "white").css("color", "black").hide();
                        },
                        paragraphsCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationparagraphs").css("background-color", "white").css("color", "black").hide();
                        },
                        wordCountLessThanMaxLengthEvent: function (currentLength, maxLength) {
                            $("#informationword").css("background-color", "white").css("color", "black").hide();
                        }
                    }
                });
  </script>

一切正常..直到我用这个编辑器更新“描述”,我把所有的表和mysql都用到UTF-8,或者至少我认为我有它。 这可能是UPDATE SQL的问题,这是代码的其余部分。 在这种情况下,我正试图在数据库中保存“Olá”。

if(mysqli_query($con, "UPDATE users SET username='" . $name1 .
       "',description='" . $descr . "',gender='" . $gender .
       "',location='" . $location . "',ocupation='" . $ocupation .
       "' WHERE user_id = '" . $_SESSION['usr_id'] . "'"))

这是DB上的结果: enter image description here

1 个答案:

答案 0 :(得分:1)

我设法解决了!我所要做的就是放一个:

mysqli_set_charset( $con, 'utf8');

之前:

if(mysqli_query($con, "UPDATE users SET username='" . $name1 . "',description='" . $descr . "',gender='" . $gender . "',location='" . $location . "',ocupation='" . $ocupation . "' WHERE user_id = '" . $_SESSION['usr_id'] . "'")) {

结果是:“Olá”