WordService.php 710 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Services\Common;
  3. class WordService
  4. {
  5. public function __construct()
  6. {
  7. $this->start();
  8. }
  9. protected function start()
  10. {
  11. ob_start();
  12. echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
  13. xmlns:w="urn:schemas-microsoft-com:office:word"
  14. xmlns="http://www.w3.org/TR/REC-html40">';
  15. }
  16. public function save($path)
  17. {
  18. echo "</html>";
  19. $data = ob_get_contents();
  20. ob_end_clean();
  21. $this->wirtefile($path, $data);
  22. ob_flush();
  23. flush();
  24. }
  25. protected function wirtefile($fn, $data)
  26. {
  27. $fp=fopen($fn, "wb");
  28. fwrite($fp, $data);
  29. fclose($fp);
  30. }
  31. }