PHP Class Ouzo\Utilities\StrSubstitutor

Datei anzeigen Open project: letsdrink/ouzo Class Usage Examples

Public Methods

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.

Private Methods

Method Description
_replace_vars ( array $match ) : string

Method Details

__construct() public method

Optionally, substitutor can use the $default when no value is found for a placeholder.
public __construct ( array $values = [], null | string $default = null )
$values array
$default null | string

replace() public method

Example: $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
public replace ( string $string ) : mixed
$string string
return mixed