From 44454b25fe4b89739168205d603f3e42073638f6 Mon Sep 17 00:00:00 2001 From: Ryan Lovelett Date: Mon, 22 Oct 2012 14:45:17 -0500 Subject: [PATCH 1/2] Ignore generated Docx and XML files --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 29a804cb59..4e3e1ee359 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ - +*.docx +*.xml /.settings /.buildpath /.project -/docs \ No newline at end of file +/docs From 167d32d2745d4dc88dc277622529797052d7cb60 Mon Sep 17 00:00:00 2001 From: Ryan Lovelett Date: Tue, 16 Jul 2013 09:42:59 -0500 Subject: [PATCH 2/2] Only encode text to UTF-8 if it is ASCII Modified implementation from discussion on PHPWord codeplex discussion boards. See http://phpword.codeplex.com/discussions/261365 for more information. --- src/Examples/Utf8Text.php | 12 ++++++++++++ src/PHPWord/Section.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/Examples/Utf8Text.php diff --git a/src/Examples/Utf8Text.php b/src/Examples/Utf8Text.php new file mode 100644 index 0000000000..dafed14ed6 --- /dev/null +++ b/src/Examples/Utf8Text.php @@ -0,0 +1,12 @@ +createSection(); +$section->addText($utf8Str); + +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('Utf8Text.docx'); \ No newline at end of file diff --git a/src/PHPWord/Section.php b/src/PHPWord/Section.php index 10d1ce6d0d..e443f49de5 100644 --- a/src/PHPWord/Section.php +++ b/src/PHPWord/Section.php @@ -109,7 +109,7 @@ public function getSettings() { * @return PHPWord_Section_Text */ public function addText($text, $styleFont = null, $styleParagraph = null) { - $givenText = utf8_encode($text); + $givenText = (mb_detect_encoding($text) === 'UTF-8') ? $text : utf8_encode($text); $text = new PHPWord_Section_Text($givenText, $styleFont, $styleParagraph); $this->_elementCollection[] = $text; return $text;