0

I need to display the content of doc file inside CKeditor. I read the content of doc file & passing it into an array line by line :

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

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

then I create an instance of 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');

the CKeditor work right now & appear on my webpage .. but without any content ? what should I right inside the foreach to passing array content into the editor ? please help =(

4

1 回答 1

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>

文档页面有更多详细信息。

于 2012-12-17T00:33:49.170 回答