PHP Class VersionPress\Utils\StringUtils

Show file Open project: versionpress/versionpress Class Usage Examples

Public Methods

Method Description
crlfize ( string $str ) : string Converts LF string to CRLF string
fillTemplateString ( array $variables, string $templateString ) : string Fills template string placeholders with variables provided in $variables array.
isSerializedValue ( $value ) : boolean Returns true if string is a serialized value (object, array, primitive types, .
pluralize ( string $string ) : string Converts given noun to plural form.
replaceFirst ( string $needle, string $replace, string $haystack ) : string Replaces the first occurence.
substringFromTo ( string $str, integer $from, integer $to ) : string An alternative to the built-in PHP function substr.
verbToPastTense ( string $verb ) : string Converts given verb to past sense. E.g., "install" -> "installed", "activate" -> "activated" etc.

Method Details

crlfize() public static method

Converts LF string to CRLF string
public static crlfize ( string $str ) : string
$str string LF line endings
return string CRLF line endings

fillTemplateString() public static method

Placeholders pattern: {{variable-name}}
public static fillTemplateString ( array $variables, string $templateString ) : string
$variables array associative array with keys as variable names.
$templateString string template string which contains placeholders for variables to be expanded.
return string templateString with expanded variable placeholders

isSerializedValue() public static method

..).
public static isSerializedValue ( $value ) : boolean
$value
return boolean

pluralize() public static method

Note: It's very, very simplified! From: https://gist.github.com/tbrianjones/ba0460cc1d55f357e00b
public static pluralize ( string $string ) : string
$string string
return string

replaceFirst() public static method

Replaces the first occurence.
public static replaceFirst ( string $needle, string $replace, string $haystack ) : string
$needle string
$replace string
$haystack string
return string

substringFromTo() public static method

The substr function needs the length of substring. This method takes bounds from-to.
public static substringFromTo ( string $str, integer $from, integer $to ) : string
$str string
$from integer
$to integer
return string

verbToPastTense() public static method

Converts given verb to past sense. E.g., "install" -> "installed", "activate" -> "activated" etc.
public static verbToPastTense ( string $verb ) : string
$verb string
return string