searchAndReplace

searchAndReplace

ADVANCED / PREMIUM BASIC

Searches and replaces a given string of text in a Word document.

Description
public searchAndReplace (string $source, string $target, string $search, string $replace [, array $options])

This method allows the substitution of plain text in a DOCX document.

Parameters

source

The path to the source Word document.

target

The path to the Word document resulting after the text replacement.

search

The string of text that you want to replace.

replace

The string of text that you want to include.

options

The possible keys and values are:

Key Type Description
document bool If true searches and replaces the string in the body of the document. The default value is true.
endnotes bool If true searches and replaces the string in the document endnotes. The default value is false.
comments bool If true searches and replaces the string in the document comments. The default value is false.
headersAndFooters bool If true searches and replaces the string in headers and footers. The default value is true.
footnotes bool If true searches and replaces the string in the document footnotes. The default value is false.
Return values

Void.

Code samples

Example #1

The resulting Word document looks like: