//call Run() method iteratively to find all matching instances. while (true) { $searchResult = $txt_search->Run(); if ($searchResult->IsFound()) { if ($step == 0) { //step 0: found "John Smith" //note that, here, 'ambient_string' and 'hlts' are not written to, //as 'e_ambient_string' and 'e_highlight' are not set. echo nl2br($searchResult->GetMatch() . "'s credit card number is: \n"); //now switch to using regular expressions to find John's credit card number $mode = $txt_search->GetMode(); $mode |= TextSearch::e_reg_expression | TextSearch::e_highlight; $txt_search->SetMode($mode); $pattern = "\\d{4}-\\d{4}-\\d{4}-\\d{4}"; //or "(\\d{4}-){3}\\d{4}" $txt_search->SetPattern($pattern); ++$step; } else { if ($step == 1) { //step 1: found John's credit card number echo nl2br(" " . $searchResult->GetMatch() . "\n"); //note that, here, 'hlts' is written to, as 'e_highlight' has been set. //output the highlight info of the credit card number. $hlts = $searchResult->GetHighlights(); $hlts->Begin($doc); while ($hlts->HasNext()) { echo nl2br("The current highlight is from page: " . $hlts->GetCurrentPageNumber() . "\n"); $hlts->Next(); } //see if there is an AMEX card number $pattern = "\\d{4}-\\d{6}-\\d{5}";