vBulletin v6.0.4

vB_Utility_String
in package
Uses vB_Utility_Trait_NoSerialize

Table of Contents

Methods

__construct()  : mixed
Constructor
__serialize()  : array<string|int, mixed>
__sleep()  : array<string|int, mixed>
__unserialize()  : void
__wakeup()  : void
areCharsetsEqual()  : bool
Are the two charsets the same
excludeMiddle()  : mixed
getCensor()  : vB_Utility_Censor
Utility function to get a string censor
getCharset()  : mixed
Get the default charset for the class
htmlentities()  : mixed
htmlspecialchars()  : mixed
Encoding aware htmlspecialchars
isDefaultCharset()  : bool
Does the charset match the default charset for the class
normalizepath()  : mixed
parseUrl()  : mixed
UTF-8 Safe Parse_url http://us3.php.net/manual/en/function.parse-url.php
strlen()  : int|false
Return the length position of the given string in characters
strpos()  : int|false
Return the position of the given string taking into account charsets
strrpos()  : int|bool
vB_Utility_String::strpos() but starting from the right.
strtolower()  : string
Returns a lower case version of the string
strtoupper()  : string
Returns a upper case version of the string
substr()  : int|bool
Return the substring in the context of the character encoding
toCharset()  : string|array<string|int, mixed>
Converts a variable from one character encoding to another.
toDefault()  : string|array<string|int, mixed>
Converts to the default charset
toUtf8()  : string|array<string|int, mixed>
Converts from the internal charset to utf8
unhtmlentities()  : mixed
unparseUrl()  : mixed

Methods

__construct()

Constructor

public __construct( $charset) : mixed
Parameters
$charset :

-- the default charset

Will throw an exception if the $charset is not an accepted value

__serialize()

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__sleep()

public __sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unserialize()

public __unserialize(mixed $serialized) : void
Parameters
$serialized : mixed

areCharsetsEqual()

Are the two charsets the same

public areCharsetsEqual(string $charset1, string $charset2) : bool

This uses the charset matching rules to look up the charsets and then compares the canoncical value for each charset to see if they match. If either charset is invalid according to the matching rule, the function will return false (even if both are the same invalid value)

Parameters
$charset1 : string
$charset2 : string
Return values
bool

excludeMiddle()

public excludeMiddle(mixed $text, mixed $minlength, mixed $prefix, mixed $suffix[, mixed $encoding = null ]) : mixed
Parameters
$text : mixed
$minlength : mixed
$prefix : mixed
$suffix : mixed
$encoding : mixed = null

getCensor()

Utility function to get a string censor

public getCensor(string $censortext) : vB_Utility_Censor

The censor class is conceptually related to the string class but needs to be seperate for various reasons. This is a simply helper function to handle the plumbing of geting instances of that class which also ensures that we can easily generate it from any place we have the string class

Parameters
$censortext : string
Return values
vB_Utility_Censor

getCharset()

Get the default charset for the class

public getCharset() : mixed
Tags
string

string -- the canonical charset for the class default

htmlentities()

public htmlentities(mixed $value[, mixed $flags = ENT_COMPAT | ENT_HTML401 ][, mixed $encoding = null ]) : mixed
Parameters
$value : mixed
$flags : mixed = ENT_COMPAT | ENT_HTML401
$encoding : mixed = null

htmlspecialchars()

Encoding aware htmlspecialchars

public htmlspecialchars(string $value[, int $flags = ENT_COMPAT | ENT_HTML401 ][, string $encoding = null ]) : mixed

This takes a string and produces an html escaped version. It uses specified charset.

Parameters
$value : string

-- string to be escaped

$flags : int = ENT_COMPAT | ENT_HTML401

-- flags per php function htmlspecialchars

$encoding : string = null

-- the browser encoding to use. Note that this is not the encoding value for the php function. Use the same values as you would use for the http/html value and would pass to this class. If null, the class default will be used.

Tags
retun

string -- escaped string

isDefaultCharset()

Does the charset match the default charset for the class

public isDefaultCharset(string $charset) : bool
Parameters
$charset : string
Tags
see
areCharsetsEqual
Return values
bool

normalizepath()

public normalizepath(string $path[, string $dir_sep = '/' ]) : mixed
Parameters
$path : string
$dir_sep : string = '/'

parseUrl()

UTF-8 Safe Parse_url http://us3.php.net/manual/en/function.parse-url.php

public parseUrl(string $url[, int $component = -1 ]) : mixed
Parameters
$url : string
$component : int = -1

strlen()

Return the length position of the given string in characters

public strlen(string $string[, string $encoding = null ]) : int|false
Parameters
$string : string

-- string to search

$encoding : string = null

-- the browser encoding to use. Use the same values as you would use for the http/html value and would pass to this class. If null, the class default will be used.

Return values
int|false

the character count of the string or false on encoding error

strpos()

Return the position of the given string taking into account charsets

public strpos(string $haystack, string $needle[, int $offset = 0 ][, string $encoding = null ]) : int|false

Note that this will return the character position and not the byte return attempting to do $string[$posvalue] will work right just often enough to pass testing. The substr function on this class will return the correct results

$haystack and $needle must by in the same encoding.

Parameters
$haystack : string

-- string to search

$needle : string

-- string to find

$offset : int = 0

-- character index to start at

$encoding : string = null

-- the browser encoding to use. Use the same values as you would use for the http/html value and would pass to this class. If null, the class default will be used.

Return values
int|false

the position of the string or false if not found

strrpos()

vB_Utility_String::strpos() but starting from the right.

public strrpos(string $haystack, string $needle[, int $offset = 0 ][, string $encoding = null ]) : int|bool

Note that this will return the character position and not the byte return attempting to do $string[$posvalue] will work right just often enough to pass testing. The substr function on this class will return the correct results

$haystack and $needle must by in the same encoding.

Parameters
$haystack : string

-- string to search

$needle : string

-- string to find

$offset : int = 0

-- character index to start at

$encoding : string = null

-- the browser encoding to use. Use the same values as you would use for the http/html value and would pass to this class. If null, the class default will be used.

Return values
int|bool

the position of the string or false if not found

strtolower()

Returns a lower case version of the string

public strtolower(string $string[, string $encoding = null ]) : string
Parameters
$string : string
$encoding : string = null

-- the browser encoding to use. If null, the class default will be used.

Return values
string

the lowercased string

strtoupper()

Returns a upper case version of the string

public strtoupper(string $string[, string $encoding = null ]) : string
Parameters
$string : string
$encoding : string = null

-- the browser encoding to use. If null, the class default will be used.

Return values
string

the uppercased string

substr()

Return the substring in the context of the character encoding

public substr(string $string, int $start[, int $length = null ][, string $encoding = null ]) : int|bool
Parameters
$string : string
$start : int

-- character index to start at

$length : int = null

-- number of characters to return. If not provided or null this will return to the end of the string

$encoding : string = null

-- the browser encoding to use. Use the same values as you would use for the http/html value and would pass to this class. If null, the class default will be used.

Return values
int|bool

the position of the string or false if not found

toCharset()

Converts a variable from one character encoding to another.

public toCharset(string|array<string|int, mixed> $value, string $sourceEncoding, string $targetEncoding) : string|array<string|int, mixed>

If the variable is a string it is converted. If it is array will attempt to recurse over it and convert any string values located. Any other types will be returned unchanged.

Note that this does not attempt to deal with reference loops so is not suitable for complex objects.

Parameters
$value : string|array<string|int, mixed>

-- The variable to convert

$sourceEncoding : string

-- The source encoding

$targetEncoding : string

-- The target encoding

Return values
string|array<string|int, mixed>

The converted variable.

toDefault()

Converts to the default charset

public toDefault(string|array<string|int, mixed> $value, string $sourceEncoding) : string|array<string|int, mixed>
Parameters
$value : string|array<string|int, mixed>

-- The variable to convert

$sourceEncoding : string

-- The source encoding

Tags
see
toCharset
Return values
string|array<string|int, mixed>

The converted variable.

toUtf8()

Converts from the internal charset to utf8

public toUtf8(string|array<string|int, mixed> $value) : string|array<string|int, mixed>
Parameters
$value : string|array<string|int, mixed>

-- The variable to convert

Tags
see
toCharset
Return values
string|array<string|int, mixed>

The converted variable.

unhtmlentities()

public unhtmlentities(mixed $value[, mixed $flags = ENT_COMPAT | ENT_HTML401 ][, mixed $encoding = null ]) : mixed
Parameters
$value : mixed
$flags : mixed = ENT_COMPAT | ENT_HTML401
$encoding : mixed = null

unparseUrl()

public unparseUrl(mixed $parsedUrl[, mixed $removeScheme = false ][, mixed $stopBefore = '' ]) : mixed
Parameters
$parsedUrl : mixed
$removeScheme : mixed = false
$stopBefore : mixed = ''

        
On this page

Search results