Method | Description | |
---|---|---|
__construct ( array $values = [], null | string $default = null ) | Creates a substitutor object that uses the given array for placeholders resolution. | |
replace ( string $string ) : mixed | Replaces placeholders {{PLACEHOLDER_NAME}} with their values. |
Method | Description | |
---|---|---|
_replace_vars ( array $match ) : string |
$strSubstitutor = new StrSubstitutor(array('NAME' => 'John', 'SURNAME' => 'Smith'));
$substituted = $strSubstitutor->replace('Hi, {{NAME}} {{SURNAME}}');
Result:
Hi, John Smith
Example:
$strSubstitutor = new StrSubstitutor(array(), 'Unknown');
$substituted = $strSubstitutor->replace('Hi, {{NAME}}');
Result:
Hi, Unknown