Skip to content

Commit f5da76e

Browse files
committed
IMPROVED : Samples\Sample01
1 parent de11f4d commit f5da76e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/Examples/Text.php renamed to samples/Sample_01_SimpleText.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<?php
2-
require_once '../PHPWord.php';
2+
3+
error_reporting(E_ALL);
4+
5+
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
6+
define('EOL', PHP_EOL);
7+
}
8+
else {
9+
define('EOL', '<br />');
10+
}
11+
12+
require_once '../src/PHPWord.php';
313

414
// New Word Document
15+
echo date('H:i:s') , " Create new PHPWord object" , EOL;
516
$PHPWord = new PHPWord();
617

718
// New portrait section
@@ -20,9 +31,18 @@
2031
$section->addText('I have only a paragraph style definition.', null, 'pStyle');
2132

2233
// Save File
34+
echo date('H:i:s') , " Write to Word2007 format" , EOL;
2335
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
24-
$objWriter->save('Text.docx');
36+
$objWriter->save(str_replace('.php', '.docx', __FILE__));
2537

38+
echo date('H:i:s') , " Write to OpenDocumentText format" , EOL;
2639
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
27-
$objWriter->save('Text.odt');
40+
$objWriter->save(str_replace('.php', '.odt', __FILE__));
41+
42+
43+
// Echo memory peak usage
44+
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
45+
46+
// Echo done
47+
echo date('H:i:s') , " Done writing file" , EOL;
2848
?>

0 commit comments

Comments
 (0)