PHP Класс yii\helpers\BaseStringHelper

Do not use BaseStringHelper. Use [[StringHelper]] instead.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Автор: Alex Makarov ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
basename ( string $path, string $suffix = '' ) : string Returns the trailing name component of a path.
byteLength ( string $string ) : integer Returns the number of bytes in the given string.
byteSubstr ( string $string, integer $start, integer $length = null ) : string Returns the portion of string specified by the start and length parameters.
countWords ( string $string ) : integer Counts words in a string
dirname ( string $path ) : string Returns parent directory's path.
endsWith ( string $string, string $with, boolean $caseSensitive = true ) : boolean Check if given string ends with specified substring.
explode ( string $string, string $delimiter = ',', mixed $trim = true, boolean $skipEmpty = false ) : array Explodes string into array, optionally trims values and skips empty ones
startsWith ( string $string, string $with, boolean $caseSensitive = true ) : boolean Check if given string starts with specified substring.
truncate ( string $string, integer $length, string $suffix = '...', string $encoding = null, boolean $asHtml = false ) : string Truncates a string to the number of characters specified.
truncateWords ( string $string, integer $count, string $suffix = '...', boolean $asHtml = false ) : string Truncates a string to the number of words specified.

Защищенные методы

Метод Описание
truncateHtml ( string $string, integer $count, string $suffix, string | boolean $encoding = false ) : string Truncate a string while preserving the HTML.

Описание методов

basename() публичный статический Метод

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 "..".
См. также: http://www.php.net/manual/en/function.basename.php
public static basename ( string $path, string $suffix = '' ) : string
$path string A path string.
$suffix string If the name component ends in suffix this will also be cut off.
Результат string the trailing name component of the given path.

byteLength() публичный статический Метод

This method ensures the string is treated as a byte array by using mb_strlen().
public static byteLength ( string $string ) : integer
$string string the string being measured for length
Результат integer the number of bytes in the given string.

byteSubstr() публичный статический Метод

This method ensures the string is treated as a byte array by using mb_substr().
См. также: http://www.php.net/manual/en/function.substr.php
public static byteSubstr ( string $string, integer $start, integer $length = null ) : string
$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 `null`, there will be no limit on length i.e. the output will be until the end of the string.
Результат string the extracted part of string, or FALSE on failure or an empty string.

countWords() публичный статический Метод

Counts words in a string
С версии: 2.0.8
public static countWords ( string $string ) : integer
$string string
Результат integer

dirname() публичный статический Метод

This method is similar to dirname() except that it will treat both \ and / as directory separators, independent of the operating system.
См. также: http://www.php.net/manual/en/function.basename.php
public static dirname ( string $path ) : string
$path string A path string.
Результат string the parent directory's path.

endsWith() публичный статический Метод

Binary and multibyte safe.
public static endsWith ( string $string, string $with, boolean $caseSensitive = true ) : boolean
$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.
Результат boolean Returns true if first input ends with second input, false otherwise

explode() публичный статический Метод

Explodes string into array, optionally trims values and skips empty ones
С версии: 2.0.4
public static explode ( string $string, string $delimiter = ',', mixed $trim = true, boolean $skipEmpty = false ) : array
$string string String to be exploded.
$delimiter string Delimiter. Default is ','.
$trim mixed Whether to trim each element. Can be: - boolean - to trim normally; - string - custom characters to trim. Will be passed as a second argument to `trim()` function. - callable - will be called for each value instead of trim. Takes the only argument - value.
$skipEmpty boolean Whether to skip empty strings between delimiters. Default is false.
Результат array

startsWith() публичный статический Метод

Binary and multibyte safe.
public static startsWith ( string $string, string $with, boolean $caseSensitive = true ) : boolean
$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.
Результат boolean Returns true if first input starts with second input, false otherwise

truncate() публичный статический Метод

Truncates a string to the number of characters specified.
public static truncate ( string $string, integer $length, string $suffix = '...', string $encoding = null, boolean $asHtml = false ) : string
$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.
Результат string the truncated string.

truncateHtml() защищенный статический Метод

Truncate a string while preserving the HTML.
С версии: 2.0.1
protected static truncateHtml ( string $string, integer $count, string $suffix, string | boolean $encoding = false ) : string
$string string The string to truncate
$count integer
$suffix string String to append to the end of the truncated string.
$encoding string | boolean
Результат string

truncateWords() публичный статический Метод

Truncates a string to the number of words specified.
public static truncateWords ( string $string, integer $count, string $suffix = '...', boolean $asHtml = false ) : string
$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.
Результат string the truncated string.