PHP Класс Ouzo\Utilities\StrSubstitutor

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
_replace_vars ( array $match ) : string

Описание методов

__construct() публичный метод

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() публичный метод

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
Результат mixed