Class yii\helpers\BaseStringHelper
Inheritance | yii\helpers\BaseStringHelper |
---|---|
Subclasses | yii\helpers\StringHelper |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseStringHelper.php |
BaseStringHelper provides concrete implementation for yii\helpers\StringHelper.
Do not use BaseStringHelper. Use yii\helpers\StringHelper instead.
Public Methods
Method | Description | Defined By |
---|---|---|
base64UrlDecode() | Decodes "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648). | yii\helpers\BaseStringHelper |
base64UrlEncode() | Encodes string into "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648). | yii\helpers\BaseStringHelper |
basename() | Returns the trailing name component of a path. | yii\helpers\BaseStringHelper |
byteLength() | Returns the number of bytes in the given string. | yii\helpers\BaseStringHelper |
byteSubstr() | Returns the portion of string specified by the start and length parameters. | yii\helpers\BaseStringHelper |
countWords() | Counts words in a string. | yii\helpers\BaseStringHelper |
dirname() | Returns parent directory's path. | yii\helpers\BaseStringHelper |
endsWith() | Check if given string ends with specified substring. | yii\helpers\BaseStringHelper |
explode() | Explodes string into array, optionally trims values and skips empty ones. | yii\helpers\BaseStringHelper |
floatToString() | Safely casts a float to string independent of the current locale. | yii\helpers\BaseStringHelper |
matchWildcard() | Checks if the passed string would match the given shell wildcard pattern. | yii\helpers\BaseStringHelper |
mb_ucfirst() | This method provides a unicode-safe implementation of built-in PHP function ucfirst() . |
yii\helpers\BaseStringHelper |
mb_ucwords() | This method provides a unicode-safe implementation of built-in PHP function ucwords() . |
yii\helpers\BaseStringHelper |
normalizeNumber() | Returns string representation of number value with replaced commas to dots, if decimal point of current locale is comma. | yii\helpers\BaseStringHelper |
startsWith() | Check if given string starts with specified substring. | yii\helpers\BaseStringHelper |
truncate() | Truncates a string to the number of characters specified. | yii\helpers\BaseStringHelper |
truncateWords() | Truncates a string to the number of words specified. | yii\helpers\BaseStringHelper |
Protected Methods
Method | Description | Defined By |
---|---|---|
truncateHtml() | Truncate a string while preserving the HTML. | yii\helpers\BaseStringHelper |
Method Details
Decodes "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648).
public static string base64UrlDecode ( $input ) | ||
$input | string | Encoded string. |
return | string | Decoded string. |
---|
Encodes string into "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648).
Note: Base 64 padding
=
may be at the end of the returned string.=
is not transparent to URL encoding.
public static string base64UrlEncode ( $input ) | ||
$input | string | The string to encode. |
return | string | Encoded string. |
---|
Returns the trailing name component of a path.
This method is similar to the php function basename()
except that it will
treat both \ and / as directory separators, independent of the operating system.
This method was mainly created to work on php namespaces. When working with real
file paths, php's basename()
should work fine for you.
Note: this method is not aware of the actual filesystem, or path components such as "..".
See also http://www.php.net/manual/en/function.basename.php.
public static string basename ( $path, $suffix = '' ) | ||
$path | string | A path string. |
$suffix | string | If the name component ends in suffix this will also be cut off. |
return | string | The trailing name component of the given path. |
---|
Returns the number of bytes in the given string.
This method ensures the string is treated as a byte array by using mb_strlen()
.
public static integer byteLength ( $string ) | ||
$string | string | The string being measured for length |
return | integer | The number of bytes in the given string. |
---|
Returns the portion of string specified by the start and length parameters.
This method ensures the string is treated as a byte array by using mb_substr()
.
public static string byteSubstr ( $string, $start, $length = null ) | ||
$string | string | The input string. Must be one character or longer. |
$start | integer | The starting position |
$length | integer | The desired portion length. If not specified or |
return | string | The extracted part of string, or FALSE on failure or an empty string. |
---|
Counts words in a string.
public static integer countWords ( $string ) | ||
$string | string |
Returns parent directory's path.
This method is similar to dirname()
except that it will treat
both \ and / as directory separators, independent of the operating system.
See also http://www.php.net/manual/en/function.basename.php.
public static string dirname ( $path ) | ||
$path | string | A path string. |
return | string | The parent directory's path. |
---|
Check if given string ends with specified substring.
Binary and multibyte safe.
public static boolean endsWith ( $string, $with, $caseSensitive = true ) | ||
$string | string | Input string to check |
$with | string | Part to search inside of the $string. |
$caseSensitive | boolean | Case sensitive search. Default is true. When case sensitive is enabled, $with must exactly match the ending of the string in order to get a true value. |
return | boolean | Returns true if first input ends with second input, false otherwise |
---|
Explodes string into array, optionally trims values and skips empty ones.
public static array explode ( $string, $delimiter = ',', $trim = true, $skipEmpty = false ) | ||
$string | string | String to be exploded. |
$delimiter | string | Delimiter. Default is ','. |
$trim | mixed | Whether to trim each element. Can be:
|
$skipEmpty | boolean | Whether to skip empty strings between delimiters. Default is false. |
Safely casts a float to string independent of the current locale.
The decimal separator will always be .
.
public static string floatToString ( $number ) | ||
$number | float|integer | A floating point number or integer. |
return | string | The string representation of the number. |
---|
Checks if the passed string would match the given shell wildcard pattern.
This function emulates \yii\helpers\fnmatch(), which may be unavailable at certain environment, using PCRE.
public static boolean matchWildcard ( $pattern, $string, $options = [] ) | ||
$pattern | string | The shell wildcard pattern. |
$string | string | The tested string. |
$options | array | Options for matching. Valid options are:
|
return | boolean | Whether the string matches pattern or not. |
---|
This method provides a unicode-safe implementation of built-in PHP function ucfirst()
.
public static string mb_ucfirst ( $string, $encoding = 'UTF-8' ) | ||
$string | string | The string to be proceeded |
$encoding | string | Optional, defaults to "UTF-8" |
This method provides a unicode-safe implementation of built-in PHP function ucwords()
.
public static string mb_ucwords ( $string, $encoding = 'UTF-8' ) | ||
$string | string | The string to be proceeded |
$encoding | string | Optional, defaults to "UTF-8" |
Returns string representation of number value with replaced commas to dots, if decimal point of current locale is comma.
public static string normalizeNumber ( $value ) | ||
$value | integer|float|string |
Check if given string starts with specified substring.
Binary and multibyte safe.
public static boolean startsWith ( $string, $with, $caseSensitive = true ) | ||
$string | string | Input string |
$with | string | Part to search inside the $string |
$caseSensitive | boolean | Case sensitive search. Default is true. When case sensitive is enabled, $with must exactly match the starting of the string in order to get a true value. |
return | boolean | Returns true if first input starts with second input, false otherwise |
---|
Truncates a string to the number of characters specified.
public static string truncate ( $string, $length, $suffix = '...', $encoding = null, $asHtml = false ) | ||
$string | string | The string to truncate. |
$length | integer | How many characters from original string to include into truncated string. |
$suffix | string | String to append to the end of truncated string. |
$encoding | string | The charset to use, defaults to charset currently used by application. |
$asHtml | boolean | Whether to treat the string being truncated as HTML and preserve proper HTML tags. This parameter is available since version 2.0.1. |
return | string | The truncated string. |
---|
Truncate a string while preserving the HTML.
protected static string truncateHtml ( $string, $count, $suffix, $encoding = false ) | ||
$string | string | The string to truncate |
$count | integer | |
$suffix | string | String to append to the end of the truncated string. |
$encoding | string|boolean |
Truncates a string to the number of words specified.
public static string truncateWords ( $string, $count, $suffix = '...', $asHtml = false ) | ||
$string | string | The string to truncate. |
$count | integer | How many words from original string to include into truncated string. |
$suffix | string | String to append to the end of truncated string. |
$asHtml | boolean | Whether to treat the string being truncated as HTML and preserve proper HTML tags. This parameter is available since version 2.0.1. |
return | string | The truncated string. |
---|