PHP Class JBZoo\Utils\Str

Show file Open project: jbzoo/utils Class Usage Examples

Public Properties

Property Type Description
$encoding string Default charset is UTF-8

Public Methods

Method Description
clean ( string $string, boolean $toLower = false, boolean $addslashes = false ) : string Make string safe - Remove UTF-8 chars - Remove all tags - Trim - Addslashes (opt) - To lower (opt)
esc ( string $string ) : string Escape UTF-8 strings
escXml ( $string ) : mixed Escape string before save it as xml content
getClassName ( mixed $object, boolean $toLower = false ) : mixed | string Get class name without namespace
htmlEnt ( string $string, boolean $encodedEntities = false ) : string Convert >, <, ', " and & to html entities, but preserves entities that are already encoded.
inc ( string $string, string $style = 'default', integer $next ) : string Increments a trailing number in a string.
ipos ( string $haystack, string $needle, integer $offset ) : integer Finds position of first occurrence of a string within another, case insensitive
isEnd ( string $haystack, string $needle, boolean $caseSensitive = false ) : boolean Checks if the $haystack ends with the text in the $needle. Case sensitive.
isMBString ( ) : boolean Check is mbstring loaded
isOverload ( ) : integer Check is mbstring oeverload standard functions
isStart ( string $haystack, string $needle, boolean $caseSensitive = false ) : boolean Checks if the $haystack starts with the text in the $needle.
istr ( string $haystack, string $needle, boolean $beforeNeedle = false ) : string Finds first occurrence of a string within another, case insensitive
len ( $string ) : integer Get string length
like ( string $pattern, string $string, boolean $caseSensitive = true ) : boolean Check if a given string matches a given pattern.
limitChars ( string $string, integer $limit = 100, string $append = '...' ) : string Truncate the string to given length of characters.
limitWords ( string $string, integer $limit = 100, string $append = '...' ) : string Truncate the string to given length of words.
low ( string $string ) : string Make a string lowercase
parseLines ( string $text, boolean $toAssoc = true ) : array Parse text by lines
pos ( string $haystack, string $needle, integer $offset ) : integer Find position of first occurrence of string in a string
random ( integer $length = 10, boolean $isReadable = true ) : string Generate ridable random string
rchr ( string $haystack, string $needle, boolean $part = null ) : string Finds the last occurrence of a character in a string within another
rpos ( string $haystack, string $needle, integer $offset ) : integer Find position of last occurrence of a string in a string
slug ( string $text = '', boolean $isCache = false ) : string Converts any accent characters to their equivalent normal characters
splitCamelCase ( string $input, string $separator = '_', boolean $toLower = true ) : string Convert camel case to human readable format
splitSql ( string $sql ) : array Splits a string of multiple queries into an array of individual queries.
stripSpace ( string $string ) : string Strip all witespaces from the given string.
strstr ( string $haystack, string $needle, boolean $beforeNeedle = false ) : string Finds first occurrence of a string within another
sub ( string $string, integer $start, integer $length ) : string Get part of string
subCount ( string $haystack, string $needle ) : integer Count the number of substring occurrences
testName2Human ( string $input ) : mixed | string Convert test name to human readable string
trim ( string $value, boolean $extendMode = false ) : string Trim whitespaces and other special chars
truncateSafe ( string $string, integer $length, string $append = '...' ) : string Truncate a string to a specified length without cutting a word off.
unique ( string $prefix = 'unique' ) : string Get unique string
up ( string $string ) : string Make a string uppercase
uuid ( ) : string Generates a universally unique identifier (UUID v4) according to RFC 4122 Version 4 UUIDs are pseudo-random!
zeroPad ( integer $number, integer $length ) : string Pads a given string with zeroes on the left.

Method Details

clean() public static method

Make string safe - Remove UTF-8 chars - Remove all tags - Trim - Addslashes (opt) - To lower (opt)
public static clean ( string $string, boolean $toLower = false, boolean $addslashes = false ) : string
$string string
$toLower boolean
$addslashes boolean
return string

esc() public static method

Escape UTF-8 strings
public static esc ( string $string ) : string
$string string
return string

escXml() public static method

Escape string before save it as xml content
public static escXml ( $string ) : mixed
$string
return mixed

getClassName() public static method

Get class name without namespace
public static getClassName ( mixed $object, boolean $toLower = false ) : mixed | string
$object mixed
$toLower boolean
return mixed | string

htmlEnt() public static method

Convert >, <, ', " and & to html entities, but preserves entities that are already encoded.
public static htmlEnt ( string $string, boolean $encodedEntities = false ) : string
$string string The text to be converted
$encodedEntities boolean
return string

inc() public static method

Used to easily create distinct labels when copying objects. The method has the following styles: - default: "Label" becomes "Label (2)" - dash: "Label" becomes "Label-2"
public static inc ( string $string, string $style = 'default', integer $next ) : string
$string string The source string.
$style string The the style (default|dash).
$next integer If supplied, this number is used for the copy, otherwise it is the 'next' number.
return string

ipos() public static method

Finds position of first occurrence of a string within another, case insensitive
public static ipos ( string $haystack, string $needle, integer $offset ) : integer
$haystack string
$needle string
$offset integer
return integer

isEnd() public static method

Checks if the $haystack ends with the text in the $needle. Case sensitive.
public static isEnd ( string $haystack, string $needle, boolean $caseSensitive = false ) : boolean
$haystack string
$needle string
$caseSensitive boolean
return boolean

isMBString() public static method

Check is mbstring loaded
public static isMBString ( ) : boolean
return boolean

isOverload() public static method

Check is mbstring oeverload standard functions
public static isOverload ( ) : integer
return integer

isStart() public static method

Checks if the $haystack starts with the text in the $needle.
public static isStart ( string $haystack, string $needle, boolean $caseSensitive = false ) : boolean
$haystack string
$needle string
$caseSensitive boolean
return boolean

istr() public static method

Finds first occurrence of a string within another, case insensitive
public static istr ( string $haystack, string $needle, boolean $beforeNeedle = false ) : string
$haystack string
$needle string
$beforeNeedle boolean
return string

len() public static method

Get string length
public static len ( $string ) : integer
$string
return integer

like() public static method

Check if a given string matches a given pattern.
public static like ( string $pattern, string $string, boolean $caseSensitive = true ) : boolean
$pattern string Parttern of string exptected
$string string String that need to be matched
$caseSensitive boolean
return boolean

limitChars() public static method

Truncate the string to given length of characters.
public static limitChars ( string $string, integer $limit = 100, string $append = '...' ) : string
$string string The variable to truncate
$limit integer The length to truncate the string to
$append string Text to append to the string IF it gets truncated, defaults to '...'
return string

limitWords() public static method

Truncate the string to given length of words.
public static limitWords ( string $string, integer $limit = 100, string $append = '...' ) : string
$string string
$limit integer
$append string
return string

low() public static method

Make a string lowercase
public static low ( string $string ) : string
$string string
return string

parseLines() public static method

Parse text by lines
public static parseLines ( string $text, boolean $toAssoc = true ) : array
$text string
$toAssoc boolean
return array

pos() public static method

Find position of first occurrence of string in a string
public static pos ( string $haystack, string $needle, integer $offset ) : integer
$haystack string
$needle string
$offset integer
return integer

random() public static method

Generate ridable random string
public static random ( integer $length = 10, boolean $isReadable = true ) : string
$length integer
$isReadable boolean
return string

rchr() public static method

Finds the last occurrence of a character in a string within another
public static rchr ( string $haystack, string $needle, boolean $part = null ) : string
$haystack string
$needle string
$part boolean
return string

rpos() public static method

Find position of last occurrence of a string in a string
public static rpos ( string $haystack, string $needle, integer $offset ) : integer
$haystack string
$needle string
$offset integer
return integer

slug() public static method

Converts any accent characters to their equivalent normal characters
public static slug ( string $text = '', boolean $isCache = false ) : string
$text string
$isCache boolean
return string

splitCamelCase() public static method

Convert camel case to human readable format
public static splitCamelCase ( string $input, string $separator = '_', boolean $toLower = true ) : string
$input string
$separator string
$toLower boolean
return string

splitSql() public static method

Single line or line end comments and multi line comments are stripped off.
public static splitSql ( string $sql ) : array
$sql string Input SQL string with which to split into individual queries.
return array

stripSpace() public static method

Strip all witespaces from the given string.
public static stripSpace ( string $string ) : string
$string string The string to strip
return string

strstr() public static method

Finds first occurrence of a string within another
public static strstr ( string $haystack, string $needle, boolean $beforeNeedle = false ) : string
$haystack string
$needle string
$beforeNeedle boolean
return string

sub() public static method

Get part of string
public static sub ( string $string, integer $start, integer $length ) : string
$string string
$start integer
$length integer
return string

subCount() public static method

Count the number of substring occurrences
public static subCount ( string $haystack, string $needle ) : integer
$haystack string
$needle string
return integer

testName2Human() public static method

Convert test name to human readable string
public static testName2Human ( string $input ) : mixed | string
$input string
return mixed | string

trim() public static method

Trim whitespaces and other special chars
public static trim ( string $value, boolean $extendMode = false ) : string
$value string
$extendMode boolean
return string

truncateSafe() public static method

Truncate a string to a specified length without cutting a word off.
public static truncateSafe ( string $string, integer $length, string $append = '...' ) : string
$string string The string to truncate
$length integer The length to truncate the string to
$append string Text to append to the string IF it gets truncated, defaults to '...'
return string

unique() public static method

Get unique string
public static unique ( string $prefix = 'unique' ) : string
$prefix string
return string

up() public static method

Make a string uppercase
public static up ( string $string ) : string
$string string
return string

uuid() public static method

Returns Version 4 UUID format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx where x is any random hex digit and Y is a random choice from 8, 9, a, or b.
See also: http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid
public static uuid ( ) : string
return string

zeroPad() public static method

Pads a given string with zeroes on the left.
public static zeroPad ( integer $number, integer $length ) : string
$number integer The number to pad
$length integer The total length of the desired string
return string

Property Details

$encoding public static property

Default charset is UTF-8
public static string $encoding
return string