Replies: 1   Views: 500
How do i searchandhighlight with an array of strings
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 SkyDweller  · 13-02-2022 - 16:46


I want to search and highlight multiple strings in the same colour. In order to do this, I want to initialise an array with all the search terms in and then run this through the searchAndHighlight function: 

So far i have tried the below foreach loop without success.

require_once 'Classes/';

$docx = new DocxUtilities();

$terms = array(

$options = array(
    'highlightColor' => 'red',
    'document' => true,
    'endnotes' => true,
    'comments' => true,
    'headersAndFooters' => true,
    'footnotes' => true,

foreach ($terms as $term) {
    $docx->searchAndHighlight('output.docx', 'output.docx', $term, $options);


Perhaps I am missing something. Any help would be most appreciated. 

Posted by admin  · 14-02-2022 - 06:39


What version and license of phpdocx are you using? Your username doesn't have any license tied, please send to contact[at] the username or email of the user that purchased the license you are using.

Also please note that the DocxUtilities class is only available in Advanced and Premium licenses. Using the searchAndHighlight method with an array was added in phpdocx 12.5 (

DocxUtilities: searchAndReplace, searchAndRemove and searchAndHighlight methods allow using arrays (Advanced and Premium licenses).