\app\framework\Component\StdLib\StdObject\StringObjectStringObject

String standard object.

This is a helper class for working with strings.

Summary

Methods
Properties
Constants
uuid()
append()
prepend()
trim()
caseLower()
caseUpper()
caseFirstUpper()
caseWordUpper()
caseFirstLower()
charFirstUpper()
nl2br()
br2nl()
stripTrailingSlash()
stripStartingSlash()
trimLeft()
trimRight()
subString()
replace()
pregReplace()
explode()
split()
hash()
htmlEntityDecode()
htmlEntityEncode()
addSlashes()
stripSlashes()
chunkSplit()
md5()
crc32()
sha1()
parseString()
quoteMeta()
format()
padLeft()
padRight()
padBoth()
repeat()
shuffle()
stripTags()
reverse()
wordWrap()
truncate()
match()
urlEncode()
urlDecode()
base64Encode()
base64Decode()
slug()
kebabCase()
snakeCase()
pascalCase()
camelCase()
sentenceCase()
singularize()
pluralize()
contains()
containsAny()
equals()
stringPosition()
startsWith()
endsWith()
longerThan()
val()
exception()
isSerialized()
__construct()
length()
wordCount()
__toString()
subStringCount()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
No public properties found
DEF_ENCODING
getObject()
is()
isNull()
isEmpty()
isObject()
isScalar()
isResource()
isArray()
isNumber()
isInteger()
isCallable()
isString()
isBool()
isBoolean()
isFile()
isReadable()
isDirectory()
isInstanceOf()
isSubClassOf()
isStringObject()
isDateTimeObject()
isFileObject()
isArrayObject()
isUrlObject()
$value
N/A
No private methods found
No private properties found
N/A

Constants

DEF_ENCODING

DEF_ENCODING

Default file encoding.

Used by multibyte string functions.

Properties

$value

$value : string

Type

string

Methods

uuid()

uuid() : string

Generate a UUID (GUID)

Returns

string

append()

append(string  $str) : $this

Appends the given string to the current string.

Parameters

string $str

String you wish to append

Returns

$this

prepend()

prepend(string  $str) : $this

Prepend the given string to the current string.

Parameters

string $str

String you wish to append

Returns

$this

trim()

trim(string|null  $char = null) : $this

Strip whitespace (or other characters) from the beginning and end of a string.

Parameters

string|null $char

Char you want to trim.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

caseLower()

caseLower() : $this

Make a string lowercase.

Returns

$this

caseUpper()

caseUpper() : $this

Make a string uppercase.

Returns

$this

caseFirstUpper()

caseFirstUpper() : $this

Transforms the whole string to lower case, but the first char will be upper case.

See also: charFirstUpper

Returns

$this

caseWordUpper()

caseWordUpper() : $this

Make the first character of every word upper.

Returns

$this

caseFirstLower()

caseFirstLower() : $this

Make the first character lowercase.

Returns

$this

charFirstUpper()

charFirstUpper() : $this

Make the first character uppercase.

See also: caseFirstUpper

Returns

$this

nl2br()

nl2br() : $this

Inserts HTML line breaks before all newlines in a string.

Returns

$this

br2nl()

br2nl() : $this

Replace HTML line break with newline character.

Returns

$this

stripTrailingSlash()

stripTrailingSlash() : $this

Strips trailing slash from the current string.

If there are two or more slashes at the end of the string, all of them will be stripped.

Returns

$this

stripStartingSlash()

stripStartingSlash() : $this

Strips a slash from the start of the string.

If there are two or more slashes at the beginning of the string, all of them will be stripped.

Returns

$this

trimLeft()

trimLeft(string  $char) : $this

Strip the $char from the start of the string.

Parameters

string $char

Char you want to trim.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

trimRight()

trimRight(string  $char) : $this

Strip the $char from the end of the string.

Parameters

string $char

Char you want to trim.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

subString()

subString(integer  $startPosition, integer  $length) : $this

Returns a substring from the current string.

Parameters

integer $startPosition

From which char position will the substring start.

integer $length

Where will the substring end. If 0 - to the end of string.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

replace()

replace(string|array  $search, string|array  $replace) : $this

Replaces the occurrences of $search inside the current string with $replace.

This function is CASE-INSENSITIVE.

Parameters

string|array $search

String, or array of strings, that will replaced.

string|array $replace

String, or array of strings, with whom $search occurrences will be replaced.

Returns

$this

pregReplace()

pregReplace(string  $pattern, mixed  $replacement, integer  $limit = -1, null  $count = null) : $this

Replace string using regex

Parameters

string $pattern

The pattern to search for. It can be either a string or an array with strings.

mixed $replacement

The string or an array with strings to replace.

integer $limit

The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).

null $count

If specified, this variable will be filled with the number of replacements done.

Returns

$this

explode()

explode(string  $delimiter, null|integer  $limit = null) : \app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

Explode the current string with the given delimiter and return ArrayObject with the exploded values.

Parameters

string $delimiter

String upon which the current string will be exploded.

null|integer $limit

Limit the number of exploded items.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

ArrayObject object containing exploded values.

split()

split(integer  $chunkSize = 1) : \app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

Split the string into chunks.

Parameters

integer $chunkSize

Size of each chunk. Set it to 1 if you want to get all the characters from the string.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

ArrayObject containing string chunks.

hash()

hash(string  $algo = 'sha1') : $this

Generate a hash value from the current string using the defined algorithm.

Parameters

string $algo

Name of the algorithm used for calculation (md5, sha1, ripemd160,...).

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

htmlEntityDecode()

htmlEntityDecode() : $this

Decode html entities in the current string.

Returns

$this

htmlEntityEncode()

htmlEntityEncode(string|null  $flags = null, string  $encoding = 'UTF-8') : $this

Convert all HTML entities to their applicable characters.

For more info visit: http://www.php.net/manual/en/function.htmlentities.php

Parameters

string|null $flags

Default flags are set to ENT_COMPAT | ENT_HTML401

string $encoding

Which encoding will be used in the conversion. Default is UTF-8.

Returns

$this

addSlashes()

addSlashes() : $this

Quote string slashes.

To remove slashes use StringObject::stripSlashes().

Returns

$this

stripSlashes()

stripSlashes() : $this

Un-quote string quoted with StringObject::addSlashes()

Returns

$this

chunkSplit()

chunkSplit(integer  $chunkSize = 76, string  $endChar = "\n") : $this

Split the string into chunks with each chunk ending with $endChar.

This function is multi-byte safe.

Parameters

integer $chunkSize

Size of each chunk.

string $endChar

String that will be appended to the end of each chunk.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

md5()

md5() : $this

Hash current string using md5 algorithm.

Returns

$this

crc32()

crc32() : $this

Calculates the crc32 polynomial of a string.

Returns

$this

sha1()

sha1() : $this

Calculate the sha1 hash of a string.

Returns

$this

quoteMeta()

quoteMeta() : $this

Quote meta characters.

Meta characters are: . \ + * ? [ ^ ] ( $ )

Returns

$this

format()

format(string|array  $args) : $this

Format the string according to the provided $format.

Parameters

string|array $args

Arguments used for string formatting. For more info visit http://www.php.net/manual/en/function.sprintf.php

Returns

$this

padLeft()

padLeft(integer  $length, string  $padString) : $this

Pad the string to a certain length with another string.

Parameters

integer $length

Length to which to pad.

string $padString

String that will be appended.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

padRight()

padRight(integer  $length, string  $padString) : $this

Pad the string to a certain length with another string.

Parameters

integer $length

Length to which to pad.

string $padString

String that will be appended.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

padBoth()

padBoth(integer  $length, string  $padString) : $this

Pad the string to a certain length with another string.

Parameters

integer $length

Length to which to pad.

string $padString

String that will be appended.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

repeat()

repeat(integer  $multiplier) : $this

Repeats the current string $multiplier times.

Parameters

integer $multiplier

How many times to repeat the string.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

shuffle()

shuffle() : $this

Shuffle characters in current string.

Returns

$this

stripTags()

stripTags(string  $whiteList = '') : $this

Remove HTML tags from the string.

Parameters

string $whiteList

A list of allowed HTML tags that you don't want to strip. Example: '

'

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

reverse()

reverse() : $this

Reverse the string.

Returns

$this

wordWrap()

wordWrap(integer  $length, string  $break = "\n", boolean  $cut = false) : $this

Wraps a string to a given number of characters using a string break character.

Parameters

integer $length

The number of characters at which the string will be wrapped.

string $break

The line is broken using the optional break parameter.

boolean $cut

If the cut is set to TRUE, the string is always wrapped at or before the specified width. So if you have a word that is larger than the given width, it is broken apart.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

truncate()

truncate(integer  $length, string  $ellipsis = '') : $this

Truncate the string to the given length without breaking words.

Parameters

integer $length

Length to which you which to trim.

string $ellipsis

Ellipsis is calculated in the string $length.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

$this

match()

match(string  $regEx, boolean  $matchAll = true) : \app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject|boolean

Preg matches current string against the given regular expression.

If you just wish if string is contained within the current string, use StringObject::contains().

Parameters

string $regEx

Regular expression to match.

boolean $matchAll

Use preg_match_all, or just preg_match. Default is preg_match_all.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject|boolean —

If there are matches, an ArrayObject with the the $matches is returned, else, false is returned.

urlEncode()

urlEncode() : $this

Url encodes the current string.

Returns

$this

urlDecode()

urlDecode() : $this

Url decodes the current string.

Returns

$this

base64Encode()

base64Encode(boolean  $webSafe = false) : $this

Encode string using base64_encode

Parameters

boolean $webSafe

Web safe encoding (replaces '+' with '-' and '/' with '_' after encoding)

Returns

$this

base64Decode()

base64Decode(boolean  $webSafe = false) : $this

Decode base64 encoded string

Parameters

boolean $webSafe

Web sage decoding (replaces '-' with '+' and '_' with '/' before decoding)

Returns

$this

slug()

slug() : $this

Create a slug

Returns

$this

kebabCase()

kebabCase() : $this

Convert string to kebab-case

Returns

$this

snakeCase()

snakeCase() : $this

Convert string to snake_case

Returns

$this

pascalCase()

pascalCase() : $this

Convert string to PascalCase

Returns

$this

camelCase()

camelCase() : $this

Convert string to camelCase

Returns

$this

sentenceCase()

sentenceCase() : $this

Convert string to kebab-case

Returns

$this

singularize()

singularize() : $this

Convert string to its singular form

Returns

$this

pluralize()

pluralize() : $this

Convert string to its plural form

Returns

$this

contains()

contains(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $needle) : boolean

Checks if a string contains the given $char.

If the $char is present, true is returned. If you wish to match a string to a regular expression use StringObject:match().

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $needle

String you wish to check if it exits within the current string.

Returns

boolean —

True if current string contains the $needle. Otherwise false is returned.

containsAny()

containsAny(array|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject  $needle) : boolean

Checks if a string contains any of the given $char.

If any of given $char is present, true is returned.

Parameters

array|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject $needle

Array of characters you wish to check

Returns

boolean —

True if current string contains the $needle. Otherwise false is returned.

equals()

equals(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Check if $string is equal to current string.

Note that this comparison is case sensitive and binary safe.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to compare.

Returns

boolean —

True if current string is equal to $string. Otherwise false is returned.

stringPosition()

stringPosition(string  $string, integer  $offset) : integer|boolean

Returns the position of the given $string inside the current string object.

Boolean false is returned if the $string is not present inside the current string. NOTE: Use type validation check in order no to mistake the position '0' (zero) for (bool) false.

Parameters

string $string
integer $offset

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

integer|boolean —

If $string is contained within the current string, the position of $string is returned, otherwise false.

startsWith()

startsWith(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Checks if the current string starts with the given $string.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to check.

Returns

boolean —

If current string starts with $string, true is returned, otherwise false.

endsWith()

endsWith(string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject  $string) : boolean

Checks if the current string ends with the given $string.

Parameters

string|\app\framework\Component\StdLib\StdObject\StringObject\StringObject $string

String to check.

Returns

boolean —

If current string ends with $string, true is returned, otherwise false.

longerThan()

longerThan(integer  $num, boolean  $inclusive = false) : boolean

Checks if the string length is great than the given length.

Parameters

integer $num

Length against which you wish to check.

boolean $inclusive

Do you want the check to be inclusive or not. Default is false (not inclusive).

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

Returns

boolean —

If current string size is longer than the given $num, true is returned, otherwise false.

val()

val(null  $value = null) : mixed

Return, or update, current standard objects value.

Parameters

null $value

If $value is set, value is updated and ArrayObject is returned.

Returns

mixed

exception()

exception(  $message) 

Throw a standard object exception.

Parameters

$message

Throws

\app\framework\Component\StdLib\StdObject\StdObjectException

isSerialized()

isSerialized(string  $value, mixed  $result = null) : boolean

Checks if a string is serialized using quick string manipulation to throw out obviously incorrect strings. Unserialize is then run on the string to perform the final verification.

Valid serialized forms are the following:

  • boolean: b:1;
  • integer: i:1;
  • double: d:0.2;
  • string: s:4:"test";
  • array: a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}
  • object: O:8:"stdClass":0:{}
  • null: N;

Parameters

string $value

Value to test for serialized form

mixed $result

Result of unserialize() of the $value

Returns

boolean —

True if $value is serialized data, otherwise false

__construct()

__construct(string|integer  $value) 

Constructor.

Set standard object value.

Parameters

string|integer $value

A string from which the StringObject instance will be created.

Throws

\app\framework\Component\StdLib\StdObject\StringObject\StringObjectException

length()

length() : integer

Get the length of the current string.

Returns

integer —

Length of current string.

wordCount()

wordCount(integer  $format) : mixed|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

Get the number of words in the string.

Parameters

integer $format

Specify the return format: 0 - return number of words 1 - return an ArrayObject containing all the words found inside the string 2 - returns an ArrayObject, where the key is the numeric position of the word inside the string and the value is the actual word itself

Returns

mixed|\app\framework\Component\StdLib\StdObject\ArrayObject\ArrayObject

An ArrayObject or integer, based on the wanted $format, with the stats about the words in the string.

__toString()

__toString() : string

To string implementation.

Returns

string —

Current string.

subStringCount()

subStringCount(string  $string, null|integer  $offset, null|integer  $length = null) : integer

Get number of string occurrences in current string.

Parameters

string $string

String to search for

null|integer $offset

The offset where to start counting

null|integer $length

The maximum length after the specified offset to search for the substring. It outputs a warning if the offset plus the length is greater than the haystack length.

Returns

integer

offsetExists()

offsetExists(mixed  $offset) : boolean

(PHP 5 &gt;= 5.0.0)<br/> Whether a offset exists

Parameters

mixed $offset

An offset to check for.

Returns

boolean —

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

offsetGet()

offsetGet(mixed  $offset) : mixed

(PHP 5 &gt;= 5.0.0)<br/> Offset to retrieve

Parameters

mixed $offset

The offset to retrieve.

Returns

mixed —

Can return all value types.

offsetSet()

offsetSet(mixed  $offset, mixed  $value) : void

(PHP 5 &gt;= 5.0.0)<br/> Offset to set

Parameters

mixed $offset

The offset to assign the value to.

mixed $value

The value to set.

offsetUnset()

offsetUnset(mixed  $offset) : void

(PHP 5 &gt;= 5.0.0)<br/> Offset to unset

Parameters

mixed $offset

The offset to unset.

getObject()

getObject() : $this

Returns an Instance of current Object

Returns

$this

is()

is(  $var) 

Parameters

$var

isNull()

isNull(mixed  $var) : boolean

Checks if given value is null.

Parameters

mixed $var

Value to check

Returns

boolean

isEmpty()

isEmpty(mixed  $var) : boolean

Checks if given value is empty.

Parameters

mixed $var

Value to check

Returns

boolean

isObject()

isObject(mixed  $var) : boolean

Check if given value is an object.

Parameters

mixed $var

Value to check

Returns

boolean

isScalar()

isScalar(mixed  $var) : boolean

Check if given value is a scalar value.

Scalar values are: integer, float, boolean and string

Parameters

mixed $var

Value to check

Returns

boolean

isResource()

isResource(mixed  $var) : boolean

Check if given value is a resource.

Parameters

mixed $var

Value to check

Returns

boolean

isArray()

isArray(  $var) : boolean

Checks if given value is an array.

Parameters

$var

Returns

boolean

isNumber()

isNumber(  $var) : boolean

Checks if value is a number.

Parameters

$var

Returns

boolean

isInteger()

isInteger(  $var) : boolean

Checks if value is an integer.

Parameters

$var

Returns

boolean

isCallable()

isCallable(  $var) : boolean

Checks whenever resource is callable.

Parameters

$var

Returns

boolean

isString()

isString(  $var) : boolean

Checks if $var is type of string.

Parameters

$var

Returns

boolean

isBool()

isBool(  $var) : boolean

Checks if $var is type of boolean.

Parameters

$var

Returns

boolean

isBoolean()

isBoolean(  $var) : boolean

This is an alias function for self::isBool

Parameters

$var

Returns

boolean

isFile()

isFile(  $var) : boolean

Checks if $var is a file.

Parameters

$var

Returns

boolean

isReadable()

isReadable(  $var) : boolean

Checks if $var is readable.

Parameters

$var

Returns

boolean

isDirectory()

isDirectory(  $var) : boolean

Checks if $var is a directory.

Parameters

$var

Returns

boolean

isInstanceOf()

isInstanceOf(mixed  $instance, string  $type) : boolean

Check if $instance is of $type.

Parameters

mixed $instance
string $type

Returns

boolean

isSubClassOf()

isSubClassOf(string|object  $subclass, string  $class) : boolean

Check if $subclass is a subclass of $class.

Parameters

string|object $subclass
string $class

Returns

boolean

isStringObject()

isStringObject(mixed  $instance) : boolean

Check if $instance is a StringObject.

Parameters

mixed $instance

Returns

boolean

isDateTimeObject()

isDateTimeObject(mixed  $instance) : boolean

Check if $instance is a DateTimeObject.

Parameters

mixed $instance

Returns

boolean

isFileObject()

isFileObject(mixed  $instance) : boolean

Check if $instance is a FileObject.

Parameters

mixed $instance

Returns

boolean

isArrayObject()

isArrayObject(mixed  $instance) : boolean

Check if $instance is an ArrayObject.

Parameters

mixed $instance

Returns

boolean

isUrlObject()

isUrlObject(mixed  $instance) : boolean

Check if $instance is a UrlObject.

Parameters

mixed $instance

Returns

boolean