Forum


Replies: 1   Views: 807
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

Hi, 

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.

<?php 
require_once 'Classes/CreateDocx.inc';

$docx = new DocxUtilities();

$terms = array(
    'data',
    'highlight'
);

$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.