Forum


Replies: 1   Views: 751
Indexer returns data with random spacing
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 14-07-2022 - 16:09

Hello,

The Indexer class returns text contents querying text (w:t) tags. A word can use one more w:t tags. Indexer divides each w:t tag using a blank space.

If you want to get words from a DOCX we recommend you to use the getWordContents method. Using this method you can query by paragraph (and other content types if needed) and return all text contents. For example:

$docx = new CreateDocxFromTemplate('document.docx');

// get the reference of the nodes to be returned
$referenceNode = array(
    'type' => 'paragraph',
);

$contents = $docx->getWordContents($referenceNode);

print_r($contents);

You can also use a wildcard:

// get the reference of the nodes to be returned
$referenceNode = array(
    'type' => '*',
);

This method returns an array with the contents.

Regards.