getWordContents

getWordContents

ADVANCED / PREMIUM TRIAL

Returns the text contents of a DOCXPath query.

Description
public getWordContents (array $referenceNode, [array $options = array()])

By default, the method returns text content as text nodes, which may include extra whitespaces from the tags. Enabling the getAsParagraphs option returns the content as paragraphs, removing these unnecessary spaces.

Parameters

referenceNode

An array to get the refence node.
The possible keys and values of this array are:

Key Type Description
type string
  • * (all, default value)
  • bookmark
  • break
  • chart
  • endnote (content reference)
  • footnote (content reference)
  • image
  • list
  • math
  • paragraph (also for bookmarks, links and lists)
  • section
  • shape
  • table
  • table-row
  • table-cell
  • table-cell-paragraph
contains string Contains a text string.
occurrence mixed
  • (int) exact occurrence (from 1)
  • (array) occurrences
  • (string) range of contents (e.g.: '2..9', '2..', '..9') or 'first()' or 'last()'
attributes array Contains a specific attribute key and value.
parent string Main document body as default, allows to set any parent or a specific one. w:body (default), '/' (any parent) or any other specific parent (/w:tbl/, /w:tc/, /w:r/...).
target string
  • document (default)
  • header
  • footer
reference array To be used with header and footer targets: positions (array) 1, 2... based on the sectPr contents order, sections (array) 1, 2..., types (array) first, even, default
customQuery string Custom xpath query, overwrites any other reference.

options

Key Type Description
getAsParagraphs bool If true, get the contents as individual paragraphs, otherwise as text nodes. Default as false.
Exceptions

Method not available.

Code samples

Example #1

Release notes
  • phpdocx 17.0:
    • occurrence option allows setting an array.
    • improved working with header and footer targets when the document include sections without headers or footers.
    • getAsParagraphs option.
  • phpdocx 15.5:
    • math type.
  • phpdocx 15.0:
    • table-row, table-cell and table-cell-paragraph types.
  • phpdocx 12.0:
    • improved working with multiple sections that contain multiple headers and footers.
  • phpdocx 9.5:
    • header and footer targets.
  • phpdocx 7.0:
    • range of elements, iterate all elements not only the first one, siblings.
  • phpdocx 6.5:
    • new method.