Method | Description | |
---|---|---|
abbreviate ( string $string, string $maxWidth ) : string | Abbreviate - abbreviates a string using ellipsis. | |
appendIfMissing ( string $string, string $suffix ) : string | Adds suffix to the string, if string does not end with the suffix already. | |
appendPrefix ( string $string, string $prefix = '' ) : string | Adds prefix to the string. | |
appendSuffix ( string $string, string $suffix = '' ) : string | Adds suffix to the string. | |
camelCaseToUnderscore ( string $string ) : string | Changes camel case string to underscored. | |
contains ( string $string, string $substring ) : boolean | Checks if string contains the substring. | |
endsWith ( string $string, string $suffix ) : boolean | Method checks if string ends with $suffix. | |
equal ( mixed $object1, mixed $object2 ) : boolean | Method checks if string representations of two objects are equal. | |
equalsIgnoreCase ( string $string1, string $string2 ) : boolean | Determines whether two strings contain the same data, ignoring the case of the letters in the strings. | |
escapeNewLines ( string $string ) : string | Changes new lines to <br> and converts special characters to HTML entities. | |
htmlEntities ( string $text ) : string | Alias for htmlentities() with UTF-8 and flags ENT_COMPAT and ENT_SUBSTITUTE (ENT_IGNORE for php <= 5.3). | |
htmlEntityDecode ( string $text ) : string | Alias for html_entity_decode() with UTF-8 and defined flag ENT_COMPAT. | |
isBlank ( string $string ) : boolean | Method checks if string is blank. | |
isNotBlank ( string $string ) : boolean | Method checks if string is not blank. | |
prependIfMissing ( string $string, string $prefix ) : string | Adds prefix to the string, if string does not start with the prefix already. | |
remove ( string $string, string $toRemove ) : mixed | Removes all occurrences of a substring from string. | |
removeAccent ( string $string ) : string | Removes accent from letters in string. | |
removePrefix ( string $string, string $prefix ) : string | Returns a new string without the given prefix. | |
removePrefixes ( string $string, array $prefixes ) : mixed | Removes prefixes defined in array from string. | |
removeSuffix ( string $string, string $suffix ) : string | Returns a new string without the given suffix. | |
replaceNth ( string $subject, string $search, string $replace, integer $nth ) : string | ||
sprintAssoc ( string $string, array $params ) : string | Replace all occurrences of placeholder in string with values from associative array. | |
sprintAssocDefault ( string $string, array $params, string $default = '' ) : string | Replace all occurrences of placeholder in string with values from associative array. | |
startsWith ( string $string, string $prefix ) : boolean | Method checks if string starts with $prefix. | |
substringAfter ( string $string, string $separator ) : string | Gets the substring after the first occurrence of a separator. The separator is not returned. | |
substringBefore ( string $string, string $separator ) : string | Gets the substring before the first occurrence of a separator. The separator is not returned. | |
tableize ( string $class ) : string | Converts a word into the format for an Ouzo table name. Converts 'ModelName' to 'model_names'. | |
trimToNull ( string $string ) : string | Removes control characters from both ends of this string returning null if the string is empty ("") after the trim or if it is null. | |
underscoreToCamelCase ( string $string ) : string | Changes underscored string to the camel case. | |
uppercaseFirst ( string $string ) : string | Uppercase first letter (multi-byte safe). |
$result = Strings::abbreviate('ouzo is great', 5);
Result:
ouzo ...
$string = 'Daenerys Targaryen';
$stringWithPrefix = Strings::appendMissingSuffix($string, ' Targaryen');
Result:
Daenerys Targaryen
$string = 'Targaryen';
$stringWithPrefix = Strings::appendPrefix($string, 'Daenerys ');
Result:
Daenerys Targaryen
$string = 'Daenerys';
$stringWithSuffix = Strings::appendSuffix($string, ' Targaryen');
Result:
Daenerys Targaryen
$string = 'LannistersAlwaysPayTheirDebts';
$underscored = Strings::camelCaseToUnderscore($string);
Result:
lannisters_always_pay_their_debts
public static camelCaseToUnderscore ( string $string ) : string | ||
$string | string | |
return | string |
$string = 'StringSuffix';
$result = Strings::endsWith($string, 'Suffix');
Result:
true
$result = Strings::equal('0123', 123);
Result:
false
$equal = Strings::equalsIgnoreCase('ABC123', 'abc123');
Result:
true
$string = "My name is Reek \nit rhymes with leek";
$escaped = Strings::escapeNewLines($string);
Result:
My name is <strong>Reek</strong>
it rhymes with leek
public static escapeNewLines ( string $string ) : string | ||
$string | string | |
return | string |
public static htmlEntities ( string $text ) : string | ||
$text | string | |
return | string |
public static htmlEntityDecode ( string $text ) : string | ||
$text | string | |
return | string |
$result = Strings::isBlank('0');
Result:
false
$result = Strings::isNotBlank('0');
Result:
true
public static isNotBlank ( string $string ) : boolean | ||
$string | string | |
return | boolean |
$string = 'Daenerys Targaryen';
$stringWithPrefix = Strings::appendMissingPrefix($string, 'Daenerys ');
Result:
Daenerys Targaryen
$string = 'winter is coming???!!!';
$result = Strings::remove($string, '???');
Result:
winter is coming!!!
$string = "śżźćółŹĘÀÁÂ";
Result:
'szzcolZEAAA'
public static removeAccent ( string $string ) : string | ||
$string | string | |
return | string |
$string = 'prefixRest';
$withoutPrefix = Strings::removePrefix($string, 'prefix');
Result:
Rest
$string = 'prefixRest';
$withoutPrefix = Strings::removePrefixes($string, array('pre', 'fix'));
Result:
Rest
$string = 'JohnSnow';
$withoutSuffix = Strings::removeSuffix($string, 'Snow');
Result:
John
$sprintfString = "This is %{what}! %{what}? This is %{place}!";
$assocArray = array(
'what' => 'madness',
'place' => 'Sparta'
);
Result:
'This is madness! madness? This is Sparta!'
$sprintfString = "This is %{what}! %{what}? This is %{place}!";
$assocArray = array(
'what' => 'madness',
'place' => 'Sparta'
);
Result:
'This is madness! madness? This is Sparta!'
$string = 'prefixRest';
$result = Strings::startsWith($string, 'prefix');
Result:
true
$class = "BigFoot";
$table = Strings::tableize($class);
Result:
BigFeet
$result = Strings::trimToNull(' ');
Result:
null
public static trimToNull ( string $string ) : string | ||
$string | string | |
return | string |
$string = 'lannisters_always_pay_their_debts';
$camelcase = Strings::underscoreToCamelCase($string);
Result:
LannistersAlwaysPayTheirDebts
public static underscoreToCamelCase ( string $string ) : string | ||
$string | string | |
return | string |
$string = "łukasz";
Result:
'Łukasz'
public static uppercaseFirst ( string $string ) : string | ||
$string | string | |
return | string |