Class yii\helpers\BaseStringHelper

Inheritanceyii\helpers\BaseStringHelper
Subclassesyii\helpers\StringHelper
Available since version2.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

Hide inherited methods

MethodDescriptionDefined By
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
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
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

Hide inherited methods

MethodDescriptionDefined By
truncateHtml() Truncate a string while preserving the HTML. yii\helpers\BaseStringHelper

Method Details

basename() public method

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.

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.

byteLength() public method

Returns the number of bytes in the given string.

This method ensures the string is treated as a byte array by using mb_strlen().

integer byteLength$string )
$string string

The string being measured for length

return integer

The number of bytes in the given string.

byteSubstr() public method

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().

See also http://www.php.net/manual/en/function.substr.php.

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 null, there will be no limit on length i.e. the output will be until the end of the string.

return string

The extracted part of string, or FALSE on failure or an empty string.

dirname() public method

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.

string dirname$path )
$path string

A path string.

return string

The parent directory's path.

endsWith() public method

Check if given string ends with specified substring.

Binary and multibyte safe.

boolean endsWith$string$with$caseSensitive true )
$string string
$with string
$caseSensitive boolean

Case sensitive search. Default is true.

return boolean

Returns true if first input ends with second input, false otherwise

explode() public method (available since version 2.0.4)

Explodes string into array, optionally trims values and skips empty ones

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:

  • 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.

startsWith() public method

Check if given string starts with specified substring.

Binary and multibyte safe.

boolean startsWith$string$with$caseSensitive true )
$string string

Input string

$with string

Part to search

$caseSensitive boolean

Case sensitive search. Default is true.

return boolean

Returns true if first input starts with second input, false otherwise

truncate() public method

Truncates a string to the number of characters specified.

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.

truncateHtml() protected method (available since version 2.0.1)

Truncate a string while preserving the HTML.

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
truncateWords() public method

Truncates a string to the number of words specified.

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.