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
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
normalizeNumber() Returns string represenation 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

Hide inherited methods

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

Method Details

base64UrlDecode() public static method (available since version 2.0.12)

Decodes "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648)

See also https://tools.ietf.org/html/rfc4648#page-7.

public static string base64UrlDecode ( $input )
$input string
base64UrlEncode() public static method (available since version 2.0.12)

Encodes string into "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648)

See also https://tools.ietf.org/html/rfc4648#page-7.

public static string base64UrlEncode ( $input )
$input string
basename() public static 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.

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.

byteLength() public static 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().

public static integer byteLength ( $string )
$string string

The string being measured for length

return integer

The number of bytes in the given string.

byteSubstr() public static 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.

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

countWords() public static method (available since version 2.0.8)

Counts words in a string

public static integer countWords ( $string )
$string string
dirname() public static 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.

public static string dirname ( $path )
$path string

A path string.

return string

The parent directory's path.

endsWith() public static method

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

explode() public static method (available since version 2.0.4)

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:

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

normalizeNumber() public static method (available since version 2.0.11)

Returns string represenation 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
startsWith() public static method

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

truncate() public static method

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.

truncateHtml() protected static method (available since version 2.0.1)

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

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.