\Gishiki\Algorithms\StringsManipulation

An helper class for string manipulation.

Summary

Methods
Properties
Constants
replaceOnce()
replaceList()
getBetween()
interpolate()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

replaceOnce()

replaceOnce(string  $pattern, string  $replacement, string  $string) : string

Convenient function that behave exactly like str_replace for the first occurrence only.

Parameters

string $pattern

the pattern to be replaced

string $replacement

the string to replace the first matched pattern

string $string

the string to search the pattern into

Returns

string —

the new string with the first matched pattern replaced

replaceList()

replaceList(array  $patterns, string  $replacement, string  $string) : string

Convenient function that behave exactly like str_replace for the first occurrence only.

Parameters

array $patterns

the list of pattern to be replaced

string $replacement

the string to replace the first matched pattern

string $string

the string to search the pattern into

Returns

string —

the new string with the first matched pattern replaced

getBetween()

getBetween(string  $string, string  $start, string  $end) : string|boolean

Get the string between two substrings.

Parameters

string $string

the string to be analyzed

string $start

the first substring

string $end

the second substring

Returns

string|boolean —

the string between the two substrings, or FALSE

interpolate()

interpolate(string  $string, array  $params) : string

Interpolate a PHP string: perform a substitution of {{name}} with the value of the $params['name'].

Note: $params['name'] can be an object that implements __toString()

Parameters

string $string
array $params

Returns

string —

the interpolated string