PHP Class JBZoo\Utils\Str

Afficher le fichier Open project: jbzoo/utils Class Usage Examples

Méthodes publiques

Свойство Type Description
$encoding string Default charset is UTF-8

Méthodes publiques

Méthode 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 méthode

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
Résultat string

esc() public static méthode

Escape UTF-8 strings
public static esc ( string $string ) : string
$string string
Résultat string

escXml() public static méthode

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

getClassName() public static méthode

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

htmlEnt() public static méthode

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
Résultat string

inc() public static méthode

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.
Résultat string

ipos() public static méthode

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
Résultat integer

isEnd() public static méthode

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
Résultat boolean

isMBString() public static méthode

Check is mbstring loaded
public static isMBString ( ) : boolean
Résultat boolean

isOverload() public static méthode

Check is mbstring oeverload standard functions
public static isOverload ( ) : integer
Résultat integer

isStart() public static méthode

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
Résultat boolean

istr() public static méthode

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
Résultat string

len() public static méthode

Get string length
public static len ( $string ) : integer
$string
Résultat integer

like() public static méthode

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
Résultat boolean

limitChars() public static méthode

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 '...'
Résultat string

limitWords() public static méthode

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
Résultat string

low() public static méthode

Make a string lowercase
public static low ( string $string ) : string
$string string
Résultat string

parseLines() public static méthode

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

pos() public static méthode

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
Résultat integer

random() public static méthode

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

rchr() public static méthode

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
Résultat string

rpos() public static méthode

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
Résultat integer

slug() public static méthode

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

splitCamelCase() public static méthode

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

splitSql() public static méthode

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.
Résultat array

stripSpace() public static méthode

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

strstr() public static méthode

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
Résultat string

sub() public static méthode

Get part of string
public static sub ( string $string, integer $start, integer $length ) : string
$string string
$start integer
$length integer
Résultat string

subCount() public static méthode

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

testName2Human() public static méthode

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

trim() public static méthode

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

truncateSafe() public static méthode

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 '...'
Résultat string

unique() public static méthode

Get unique string
public static unique ( string $prefix = 'unique' ) : string
$prefix string
Résultat string

up() public static méthode

Make a string uppercase
public static up ( string $string ) : string
$string string
Résultat string

uuid() public static méthode

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
Résultat string

zeroPad() public static méthode

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
Résultat string

Property Details

$encoding public_oe static_oe property

Default charset is UTF-8
public static string $encoding
Résultat string