How to save text to a document using PHPWord from ckeditor?

how to save text written in ckeditor in a document using PHPWord library, c formatting?
April 19th 20 at 12:49
1 answer
April 19th 20 at 12:51
Make a POST request with the text that the user typed into the editor and save the file.

$phpWord = new \PhpOffice\PhpWord\PhpWord();

// Add a section (in Word all the text is divided into sections)
$section = $pw->addSection();

// Add our HTML section
$html = $_POST['content'] ?? ";
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);

// Save the file
$pw->save("html-to-doc.docx", "Word2007");


Since we file insert not just text, but HTML, the formatting will remain as in js editor.

Find more questions by tags PHP