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 =(

m.hyari
  • 41
  • 7

1 Answers1

1

.doc files are zipped up and cannot be read like this, by line. Consider using PHPWord to get access to the contents inside.

EDIT: Looks like PHPDoc can only write and not read, upon further investigation.

PHP tools are very deficient in this area. Your best bet is to use something like DocVert to do your file conversions on the command line. THEN you could load that document inside CKEditor.

EDIT: after OP's comment:

let's consider it's a txt file ... I need the Ckeditor method

Load your decoded HTML content into a Textarea, and give this textarea an HTML ID or class: $textarea_content = htmlspecialchars_decode(file_get_contents('text.doc'));

Then, in your HTML, call the CKEditor inside a JavaScript tag to replace the textarea with the editor:

<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>

The documentation page has a lot more details.

Aditya M P
  • 5,127
  • 7
  • 41
  • 72