Forum


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

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

Hello,

What version and license of phpdocx are you using? Your username doesn't have any license tied, please send to contact[at]phpdocx.com 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 (https://www.phpdocx.com/news/post/phpdocx-v12-5-release-notes/224):

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

Regards.