【问题标题】:how to display an array content inside CKeditor?如何在 CKeditor 中显示数组内容?
【发布时间】:2012-12-17 00:29:11
【问题描述】:

我需要在 CKeditor 中显示 doc 文件的内容。 我读取了 doc 文件的内容并将其逐行传递到数组中:

$rs = fopen("text.doc", "r");

            while ($line = fgets($rs, 1024)) {
                $this->data[] = $line . "<BR>";
            }

然后我创建一个 CKeditor 的实例:

include_once("ckeditor/ckeditor.php");
    $CKeditor = new CKeditor();
    $CKeditor->basePath = '/ckeditor/';
    foreach ($this->data as $value) {
                 //what should I write here
    }
    $CKeditor->editor('editor1');

CKeditor 现在可以工作并出现在我的网页上.. 但没有任何内容? 我应该在 foreach 中将数组内容传递到编辑器中吗? 请帮忙=(

【问题讨论】:

    标签: php ckeditor


    【解决方案1】:

    .doc 文件被压缩,不能像这样按行读取。考虑使用PHPWord 来访问里面的内容。

    编辑:经过进一步调查,看起来 PHPDoc 只能写不能读。

    PHP 工具在这方面非常缺乏。最好的办法是使用 DocVert 之类的东西在命令行上进行文件转换。那么你可以在 CKEditor 中加载该文档。

    编辑:在 OP 的评论之后:

    让我们认为它是一个 txt 文件...我需要 Ckeditor 方法

    将解码后的 HTML 内容加载到一个 Textarea 中,并给这个 textarea 一个 HTML ID 或类: $textarea_content = htmlspecialchars_decode(file_get_contents('text.doc'));

    然后,在您的 HTML 中,调用 JavaScript 标记内的 CKEditor 以将 textarea 替换为编辑器:

    <html>
    <head>
    <!-- include CKEditor in a <script> tag first -->
    <script type="text/javascript">
        window.onload = function()
        {
            CKEDITOR.replace( 'editor1' );
        };
    </script>
    </head>
    <body>
    <textarea id="editor1" name="editor1"><?php echo $textarea_content ?></textarea>
    </body>
    

    documentation page 有更多详细信息。

    【讨论】:

    • 问题不是doc文件问题是如何传递数组
    • 你好像不明白。 PHP 无法原生读取该 .doc 文件。它不是一个简单的文本文件。 '传递数组'是这里最少的问题。
    • 让我们认为它是一个 txt 文件...我需要 Ckeditor 方法
    猜你喜欢
    • 2022-01-18
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多