PHP Class luya\helpers\StringHelper

This class extends the {{yii\helpers\StringHelper}} class by some helpful methods.
Since: 1.0.0-beta7
Author: Basil Suter ([email protected])
Inheritance: extends yii\helpers\StringHelper
Mostrar archivo Open project: luyadev/luya Class Usage Examples

Public Methods

Method Description
contains ( string | array $needle, string $haystack, boolean $strict = false ) : boolean Check whether a char or word exists in a string or not.
replaceFirst ( string $search, string $replace, string $subject ) : mixed Replace only the first occurance found inside the string.
typeCast ( mixed $string ) : mixed TypeCast a string to its specific types.

Method Details

contains() public static method

This method is case sensitive. The need can be an array with multiple chars or words who are going to look up in the haystack string. If an array of needle words is provided the $strict parameter defines whether all need keys must be found in the string to get the true response or if just one of the keys are found the response is already true.
Since: 1.0.0-rc1
public static contains ( string | array $needle, string $haystack, boolean $strict = false ) : boolean
$needle string | array The char or word to find in the $haystack. Can be an array to multi find words or char in the string.
$haystack string The haystack where the $needle string should be looked up.
$strict boolean If an array of needles is provided the $strict parameter defines whether all keys must be found ($strict = true) or just one result must be found ($strict = false).
return boolean If an array of values is provided the response may change depending on $findAll

replaceFirst() public static method

The replace first method is *case sensitive*. php StringHelper::replaceFirst('abc', '123', 'abc abc abc'); // returns "123 abc abc"
Since: 1.0.0-rc1
public static replaceFirst ( string $search, string $replace, string $subject ) : mixed
$search string Search string to look for.
$replace string Replacement value for the first found occurrence.
$subject string The string you want to look up to replace the first element.
return mixed Replaced string

typeCast() public static method

Arrays will passed to to the {{luya\helpers\ArrayHelper::typeCast}} class.
public static typeCast ( mixed $string ) : mixed
$string mixed The input string to type cast. Arrays will be passted to {{luya\helpers\ArrayHelper::typeCast}}.
return mixed The new type casted value, if the input is an array the output is the typecasted array.