AhoCorasick
PHP implementation of the Aho-Corasick string search algorithm
Loading...
Searching...
No Matches
AhoCorasick\MultiStringReplacer Class Reference

Search and replace functionality. More...

+ Inheritance diagram for AhoCorasick\MultiStringReplacer:
+ Collaboration diagram for AhoCorasick\MultiStringReplacer:

Public Member Functions

 __construct (array $replacePairs)
 Constructor.
 
 searchAndReplace ( $text)
 Search and replace a set of keywords in some text.
 
- Public Member Functions inherited from AhoCorasick\MultiStringMatcher
 getKeywords ()
 Accessor for the search keywords.
 
 nextState ( $currentState, $inputChar)
 Map the current state and input character to the next state.
 
 searchIn ( $text)
 Locate the search keywords in some text.
 

Protected Attributes

 $replacePairs = []
 
- Protected Attributes inherited from AhoCorasick\MultiStringMatcher
 $searchKeywords = []
 
 $numStates = 1
 
 $outputs = []
 
 $noTransitions = []
 
 $yesTransitions = []
 

Additional Inherited Members

- Protected Member Functions inherited from AhoCorasick\MultiStringMatcher
 computeYesTransitions ()
 Get the state transitions which the string-matching automaton shall make as it advances through input text.
 
 computeNoTransitions ()
 Get the state transitions which the string-matching automaton shall make when a partial match proves false.
 

Detailed Description

Search and replace functionality.

Constructor & Destructor Documentation

◆ __construct()

AhoCorasick\MultiStringReplacer::__construct ( array  $replacePairs)

Constructor.

Parameters
array$replacePairsarray of ( 'from' => 'to' ) replacement pairs.

Reimplemented from AhoCorasick\MultiStringMatcher.

Member Function Documentation

◆ searchAndReplace()

AhoCorasick\MultiStringReplacer::searchAndReplace (   $text)

Search and replace a set of keywords in some text.

Parameters
string$textThe string to search in.
Returns
string The input text with replacements.
Example:
$replacer = new MultiStringReplacer( array( 'csh' => 'sea shells' ) );
$replacer->searchAndReplace( 'She sells csh by the sea shore.' );
// result: 'She sells sea shells by the sea shore.'
Search and replace functionality.
Definition MultiStringReplacer.php:26

The documentation for this class was generated from the following file: