PHP 클래스 Ouzo\Utilities\Strings

파일 보기 프로젝트 열기: letsdrink/ouzo 1 사용 예제들

공개 메소드들

메소드 설명
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).

메소드 상세

abbreviate() 공개 정적인 메소드

Example: $result = Strings::abbreviate('ouzo is great', 5); Result: ouzo ...
public static abbreviate ( string $string, string $maxWidth ) : string
$string string
$maxWidth string
리턴 string

appendIfMissing() 공개 정적인 메소드

Example: $string = 'Daenerys Targaryen'; $stringWithPrefix = Strings::appendMissingSuffix($string, ' Targaryen'); Result: Daenerys Targaryen
public static appendIfMissing ( string $string, string $suffix ) : string
$string string
$suffix string
리턴 string

appendPrefix() 공개 정적인 메소드

Example: $string = 'Targaryen'; $stringWithPrefix = Strings::appendPrefix($string, 'Daenerys '); Result: Daenerys Targaryen
public static appendPrefix ( string $string, string $prefix = '' ) : string
$string string
$prefix string
리턴 string

appendSuffix() 공개 정적인 메소드

Example: $string = 'Daenerys'; $stringWithSuffix = Strings::appendSuffix($string, ' Targaryen'); Result: Daenerys Targaryen
public static appendSuffix ( string $string, string $suffix = '' ) : string
$string string
$suffix string
리턴 string

camelCaseToUnderscore() 공개 정적인 메소드

Example: $string = 'LannistersAlwaysPayTheirDebts'; $underscored = Strings::camelCaseToUnderscore($string); Result: lannisters_always_pay_their_debts
public static camelCaseToUnderscore ( string $string ) : string
$string string
리턴 string

contains() 공개 정적인 메소드

Checks if string contains the substring.
public static contains ( string $string, string $substring ) : boolean
$string string
$substring string
리턴 boolean

endsWith() 공개 정적인 메소드

Example: $string = 'StringSuffix'; $result = Strings::endsWith($string, 'Suffix'); Result: true
public static endsWith ( string $string, string $suffix ) : boolean
$string string
$suffix string
리턴 boolean

equal() 공개 정적인 메소드

Example: $result = Strings::equal('0123', 123); Result: false
public static equal ( mixed $object1, mixed $object2 ) : boolean
$object1 mixed
$object2 mixed
리턴 boolean

equalsIgnoreCase() 공개 정적인 메소드

Example: $equal = Strings::equalsIgnoreCase('ABC123', 'abc123'); Result: true
public static equalsIgnoreCase ( string $string1, string $string2 ) : boolean
$string1 string
$string2 string
리턴 boolean

escapeNewLines() 공개 정적인 메소드

Example: $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
리턴 string

htmlEntities() 공개 정적인 메소드

Alias for htmlentities() with UTF-8 and flags ENT_COMPAT and ENT_SUBSTITUTE (ENT_IGNORE for php <= 5.3).
public static htmlEntities ( string $text ) : string
$text string
리턴 string

htmlEntityDecode() 공개 정적인 메소드

Alias for html_entity_decode() with UTF-8 and defined flag ENT_COMPAT.
public static htmlEntityDecode ( string $text ) : string
$text string
리턴 string

isBlank() 공개 정적인 메소드

Example: $result = Strings::isBlank('0'); Result: false
public static isBlank ( string $string ) : boolean
$string string
리턴 boolean

isNotBlank() 공개 정적인 메소드

Example: $result = Strings::isNotBlank('0'); Result: true
public static isNotBlank ( string $string ) : boolean
$string string
리턴 boolean

prependIfMissing() 공개 정적인 메소드

Example: $string = 'Daenerys Targaryen'; $stringWithPrefix = Strings::appendMissingPrefix($string, 'Daenerys '); Result: Daenerys Targaryen
public static prependIfMissing ( string $string, string $prefix ) : string
$string string
$prefix string
리턴 string

remove() 공개 정적인 메소드

Example: $string = 'winter is coming???!!!'; $result = Strings::remove($string, '???'); Result: winter is coming!!!
public static remove ( string $string, string $toRemove ) : mixed
$string string
$toRemove string
리턴 mixed

removeAccent() 공개 정적인 메소드

Example: $string = "śżźćółŹĘÀÁÂ"; Result: 'szzcolZEAAA'
public static removeAccent ( string $string ) : string
$string string
리턴 string

removePrefix() 공개 정적인 메소드

Example: $string = 'prefixRest'; $withoutPrefix = Strings::removePrefix($string, 'prefix'); Result: Rest
public static removePrefix ( string $string, string $prefix ) : string
$string string
$prefix string
리턴 string

removePrefixes() 공개 정적인 메소드

Example: $string = 'prefixRest'; $withoutPrefix = Strings::removePrefixes($string, array('pre', 'fix')); Result: Rest
public static removePrefixes ( string $string, array $prefixes ) : mixed
$string string
$prefixes array
리턴 mixed

removeSuffix() 공개 정적인 메소드

Example: $string = 'JohnSnow'; $withoutSuffix = Strings::removeSuffix($string, 'Snow'); Result: John
public static removeSuffix ( string $string, string $suffix ) : string
$string string
$suffix string
리턴 string

replaceNth() 공개 정적인 메소드

public static replaceNth ( string $subject, string $search, string $replace, integer $nth ) : string
$subject string
$search string
$replace string
$nth integer
리턴 string

sprintAssoc() 공개 정적인 메소드

Example: $sprintfString = "This is %{what}! %{what}? This is %{place}!"; $assocArray = array( 'what' => 'madness', 'place' => 'Sparta' ); Result: 'This is madness! madness? This is Sparta!'
public static sprintAssoc ( string $string, array $params ) : string
$string string
$params array
리턴 string

sprintAssocDefault() 공개 정적인 메소드

When no value for placeholder is found in array, a default empty value is used if not otherwise specified. Example: $sprintfString = "This is %{what}! %{what}? This is %{place}!"; $assocArray = array( 'what' => 'madness', 'place' => 'Sparta' ); Result: 'This is madness! madness? This is Sparta!'
public static sprintAssocDefault ( string $string, array $params, string $default = '' ) : string
$string string
$params array
$default string
리턴 string

startsWith() 공개 정적인 메소드

Example: $string = 'prefixRest'; $result = Strings::startsWith($string, 'prefix'); Result: true
public static startsWith ( string $string, string $prefix ) : boolean
$string string
$prefix string
리턴 boolean

substringAfter() 공개 정적인 메소드

Gets the substring after the first occurrence of a separator. The separator is not returned.
public static substringAfter ( string $string, string $separator ) : string
$string string
$separator string
리턴 string

substringBefore() 공개 정적인 메소드

Gets the substring before the first occurrence of a separator. The separator is not returned.
public static substringBefore ( string $string, string $separator ) : string
$string string
$separator string
리턴 string

tableize() 공개 정적인 메소드

Example: $class = "BigFoot"; $table = Strings::tableize($class); Result: BigFeet
public static tableize ( string $class ) : string
$class string
리턴 string

trimToNull() 공개 정적인 메소드

Example: $result = Strings::trimToNull(' '); Result: null
public static trimToNull ( string $string ) : string
$string string
리턴 string

underscoreToCamelCase() 공개 정적인 메소드

Example: $string = 'lannisters_always_pay_their_debts'; $camelcase = Strings::underscoreToCamelCase($string); Result: LannistersAlwaysPayTheirDebts
public static underscoreToCamelCase ( string $string ) : string
$string string
리턴 string

uppercaseFirst() 공개 정적인 메소드

Example: $string = "łukasz"; Result: 'Łukasz'
public static uppercaseFirst ( string $string ) : string
$string string
리턴 string