PHP Class Jyxo\StringUtil

Author: Jan Tichý
Author: Jakub Tománek
Author: Jaroslav Hanslík
Datei anzeigen Open project: jyxo/php Class Usage Examples

Public Methods

Method Description
crc ( string $string ) : integer Generates a crc checksum same on 32 and 64-bit platforms.
cut ( string $string, integer $max = 50, string $etc = '...' ) : string Trims a string to given length.
cutWords ( string $string, integer $length = 25, string $etc = '...' ) : string Trims all words in a string longer than given length.
escape ( string $string, integer $quoteStyle = ENT_QUOTES, boolean $doubleEncode = false ) : string Htmlspecialchars function alias with some parameters automatically set.
fixLineEnding ( string $string, string $lineEnd = " " ) : string Fixes and unifies line endings in a string.
formatBytes ( float $size, string $decimalPoint = ',', string $thousandsSeparator = ' ' ) : string Converts given size in bytes to kB, MB, GB, TB or PB and appends the appropriate unit.
lcfirst ( string $string ) : string Converts first character of a string to lowercase.
obfuscateEmail ( string $email, boolean $comment = false ) : string Obfuscates an email address.
random ( integer $length ) : string Generates a random string of given length.

Method Details

crc() public static method

Generates a crc checksum same on 32 and 64-bit platforms.
public static crc ( string $string ) : integer
$string string Input string
return integer

cut() public static method

Trims at word boundaries (all non-alphanumeric characters are considered delimiters). If the given string is trimmed, an "etc" is added at the end. Its length is also considered.
public static cut ( string $string, integer $max = 50, string $etc = '...' ) : string
$string string Trimmed string
$max integer Maximum length
$etc string "etc" definition
return string

cutWords() public static method

String is delimited by whitespaces. If a word is trimmed, an "etc" is added at the end. Its length is also considered.
public static cutWords ( string $string, integer $length = 25, string $etc = '...' ) : string
$string string Processed string
$length integer Maximum word length
$etc string "etc" definition
return string

escape() public static method

Htmlspecialchars function alias with some parameters automatically set.
public static escape ( string $string, integer $quoteStyle = ENT_QUOTES, boolean $doubleEncode = false ) : string
$string string Input string
$quoteStyle integer Quote style
$doubleEncode boolean Prevent from double encoding
return string

fixLineEnding() public static method

Fixes and unifies line endings in a string.
public static fixLineEnding ( string $string, string $lineEnd = " " ) : string
$string string String to fix
$lineEnd string Desired line ending
return string

formatBytes() public static method

Converts given size in bytes to kB, MB, GB, TB or PB and appends the appropriate unit.
public static formatBytes ( float $size, string $decimalPoint = ',', string $thousandsSeparator = ' ' ) : string
$size float Input size
$decimalPoint string Decimal point
$thousandsSeparator string Thousands separator
return string

lcfirst() public static method

Works correctly with multibyte encodings.
public static lcfirst ( string $string ) : string
$string string Input string
return string

obfuscateEmail() public static method

Obfuscates an email address.
public static obfuscateEmail ( string $email, boolean $comment = false ) : string
$email string Email address
$comment boolean Put a comment into the address
return string

random() public static method

Generates a random string of given length.
public static random ( integer $length ) : string
$length integer String length
return string