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