PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

Non-breaking Hyphens disappear

Open Mifty opened this issue 3 years ago • 1 comments

Describe the Bug

When you load a word document containing non-breaking hyphens, the hyphens are stripped from the loaded text. So for example if we had "2-6" with the hyphen being a non-breaking hyphen, PHPWord loads the text as "26" instead of "2-6". This only happens with non-breaking hyphens. Regular hyphens work as expected

Steps to Reproduce

  1. create a word docx file containing a non-breaking hyphen. You can use the following video to learn how to create a non-breaking hyphen: https://www.youtube.com/watch?v=fHGTvV-j6hM

  2. save the the docx file and then load the docx file using the sample code below

<?php
require __DIR__ . '/vendor/autoload.php';

$phpWord = IOFactory::createReader('Word2007')->load($fileLocation);
// load the sections
        foreach ($phpWord->getSections() as $section) {
            // load the elements in the section
            foreach ($section->getElements() as $element) {
                   if (get_class($element) === 'PhpOffice\PhpWord\Element\TextRun'){
                       // now print out the textrun and you will see that the non-breaking hyphen has disappeared in the output string
                       echo $element;
                       die();
                       
                    }      
                }
          }   

Expected Behavior

I would expect PHPWord to read non-breaking hyphens just like it reads regular hyphens

Current Behavior

Right now, the non-breaking hyphens disappear like they are not present in the word document

Context

Please fill in your environment information:

  • PHP Version: 7.4
  • PHPWord Version: 0.18.2

Mifty avatar Nov 04 '21 03:11 Mifty