【问题标题】:CKEditor not saving in utf-8CKEditor 不保存在 utf-8
【发布时间】:2017-03-07 10:39:30
【问题描述】:

我会尽量快速简单地理解它。我的 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'] . "'"))

这是数据库上的结果:

【问题讨论】:

  • 确保列/表为CHARACTER SET utf8(或utf8mb4)

标签: php html mysql utf-8 ckeditor


【解决方案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á”

【讨论】:

    猜你喜欢
    • 2019-08-08
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-04
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多