class vB5_String

String

Methods

static string
convertIntToUtf8(integer $intval)

Converts an integer into a UTF-8 character string

static string
fetchWordWrappedString(integer $text, string $limit, string $wraptext = ' ')

Attempts to intelligently wrap excessively long strings onto multiple lines

static string
htmlSpecialCharsUni($text, $entities = true)

Unicode-safe version of htmlspecialchars()

static 
htmlSpecialCharsUniCallback($matches)

No description

static bool
isEmpty(string $val)

No description

static boolean
isValidEmail(string $email)

Tests a string to see if it's a valid email address

static string
stripBlankAscii($text, $replace, $blankasciistrip)

Replaces any non-printing ASCII characters with the specified string.

static 
stripos($haystack, $needle, $offset = 0)

Case-insensitive version of strpos(). Defined if it does not exist.

static string
unHtmlSpecialChars(string $text, boolean $doUniCode = false)

Returns a string where HTML entities have been converted back to their original characters

static string
vbChop(string $string, integer $length)

Chops off a string at a specific length, counting entities as once character and using multibyte-safe functions if available.

static integer
vbStrlen(string $string, boolean $unHtmlSpecialChars = false)

Attempts to do a character-based strlen on data that might contain HTML entities.

static string,
getTempCharset()

This is a temporary function used to get the stylevar 'charset' (added for presentation).

static string,
getCharset()

This gets the charset based on the current language

static string
convertUrlencodedUnicode(Mixed $text)

Converts Unicode entities of the format %uHHHH where each H is a hexadecimal character to &#DDDD; or the appropriate UTF-8 character based on current charset.

static string
convertUnicodeCharToCharset(integer $unicode_int, string $charset)

Converts a single unicode character to the desired character set if possible.

static string
urlencodeUni(string $str)

Poor man's urlencode that only encodes specific characters and preserves unicode.

static string
jsonEncode(mixed $value, int $options = 0)

Encodes a value as a JSON string, attempting to correct invalid UTF8 characters that would otherwise make PHP's json_encode fail.

static string
toUtf8(string $in, string $charset = false, bool $strip = true)

Converts a string to utf8

static string
toCharset(string|array $in, string $in_encoding, string $target_encoding = false, string $do_ncr = true)

Converts a string from one character encoding to another.

static string
stripncrs(string $str)

Strips NCRs from a string.

static bool
isPcreUnicode()

Checks if PCRE supports unicode

static string
ncrencode(string $str, bool $skip_ascii = false, bool $skip_win = false)

Converts a UTF-8 string into unicode NCR equivelants.

static string
ncrencodeMatches($matches, $skip_ascii = false, $skip_win = false)

NCR encodes matches from a preg_replace.

static int
ordUni(string $chr)

Gets the Unicode Ordinal for a UTF-8 character.

static mixed
parseUrl(string $url, int $component = -1)

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

static 
jsonEncodeLocalCharset($value, $options = 0, $depth = 512)

No description

static string
encodeUtf8Url(string $url)

Encode a UTF-8 Encoded URL and urlencode it while leaving control characters in tact.

static 
decodeUtf8Url($url)

No description

static string
fetchCensoredText(string $text)

Replaces any instances of words censored in $options['censorwords'] with $options['censorchar']

static string
fetchTrimmedTitle(string $title, integer $chars, boolean $append = true)

Trims a string to the specified length while keeping whole words.

static 
isVbCharset($charset)

No description

static 
areCharsetsEqual($charset1, $charset2)

No description

static string
stripBbcode(string $message, boolean $stripquotes = false, boolean $fast_and_dirty = false, boolean $showlinks = true, boolean $stripimg = false, boolean $keepquotetags = false)

Strips away bbcode from a given string, leaving plain text

Details

at line 32
static string convertIntToUtf8(integer $intval)

Converts an integer into a UTF-8 character string

Parameters

integer $intval Integer to be converted

Return Value

string

at line 74
static string fetchWordWrappedString(integer $text, string $limit, string $wraptext = ' ')

Attempts to intelligently wrap excessively long strings onto multiple lines

Parameters

integer $text max word wrap length
string $limit Text to be wrapped
string $wraptext Text to insert at the wrap point

Return Value

string

at line 100
static string htmlSpecialCharsUni($text, $entities = true)

Unicode-safe version of htmlspecialchars()

Parameters

$text
$entities

Return Value

string

at line 128
static protected htmlSpecialCharsUniCallback($matches)

Parameters

$matches

at line 170
static bool isEmpty(string $val)

Parameters

string $val

Return Value

bool

at line 182
static boolean isValidEmail(string $email)

Tests a string to see if it's a valid email address

Parameters

string $email Email address

Return Value

boolean

at line 198
static string stripBlankAscii($text, $replace, $blankasciistrip)

Replaces any non-printing ASCII characters with the specified string.

This also supports removing Unicode characters automatically when the entered value is >255 or starts with a 'u'.

Parameters

$text
$replace
$blankasciistrip

Return Value

string

at line 251
static stripos($haystack, $needle, $offset = 0)

Case-insensitive version of strpos(). Defined if it does not exist.

Parameters

$haystack
$needle
$offset

at line 271
static string unHtmlSpecialChars(string $text, boolean $doUniCode = false)

Returns a string where HTML entities have been converted back to their original characters

Parameters

string $text String to be parsed
boolean $doUniCode Convert unicode characters back from HTML entities?

Return Value

string

at line 295
static string vbChop(string $string, integer $length)

Chops off a string at a specific length, counting entities as once character and using multibyte-safe functions if available.

Parameters

string $string String to chop
integer $length Number of characters to chop at

Return Value

string Chopped string

at line 359
static integer vbStrlen(string $string, boolean $unHtmlSpecialChars = false)

Attempts to do a character-based strlen on data that might contain HTML entities.

By default, it only converts numeric entities but can optional convert ", <, etc. Uses a multi-byte aware function to do the counting if available.

Parameters

string $string String to be measured
boolean $unHtmlSpecialChars If true, run unhtmlspecialchars on string to count " as one, etc.

Return Value

integer Length of string

at line 381
static string, getTempCharset()

This is a temporary function used to get the stylevar 'charset' (added for presentation).

Return Value

string, stylevar charset value

at line 400
static string, getCharset()

This gets the charset based on the current language

Return Value

string, stylevar charset value

at line 429
static string convertUrlencodedUnicode(Mixed $text)

Converts Unicode entities of the format %uHHHH where each H is a hexadecimal character to &#DDDD; or the appropriate UTF-8 character based on current charset.

Parameters

Mixed $text array or text

Return Value

string Decoded text

at line 480
static string convertUnicodeCharToCharset(integer $unicode_int, string $charset)

Converts a single unicode character to the desired character set if possible.

Attempts to use iconv if it's available. Callback function for the regular expression in vB5_String::convertUrlencodedUnicode().

Parameters

integer $unicode_int Unicode code point value
string $charset Character to convert to

Return Value

string Character in desired character set or as an HTML entity

at line 506
static string urlencodeUni(string $str)

Poor man's urlencode that only encodes specific characters and preserves unicode.

Use urldecode() to decode.

Parameters

string $str String to encode

Return Value

string Encoded string

at line 527
static string jsonEncode(mixed $value, int $options = 0)

Encodes a value as a JSON string, attempting to correct invalid UTF8 characters that would otherwise make PHP's json_encode fail.

Parameters

mixed $value Value to encode
int $options Options for json_encode

Return Value

string Encoded string

at line 555
static string toUtf8(string $in, string $charset = false, bool $strip = true)

Converts a string to utf8

Parameters

string $in The variable to clean
string $charset The source charset
bool $strip Whether to strip invalid utf8 if we couldn't convert

Return Value

string The reencoded string

at line 614
static string toCharset(string|array $in, string $in_encoding, string $target_encoding = false, string $do_ncr = true)

Converts a string from one character encoding to another.

If the target encoding is not specified then it will be resolved from the current language settings.

Parameters

string|array $in The string/array to convert
string $in_encoding The source encoding
string $target_encoding The target encoding -- defaults to the current encoding
string $do_ncr Whether to do ncr encoding of special characters.

Return Value

string The target encoding

at line 694
static string stripncrs(string $str)

Strips NCRs from a string.

Parameters

string $str The string to strip from

Return Value

string The result

at line 704
static protected bool isPcreUnicode()

Checks if PCRE supports unicode

Return Value

bool

at line 724
static string ncrencode(string $str, bool $skip_ascii = false, bool $skip_win = false)

Converts a UTF-8 string into unicode NCR equivelants.

Parameters

string $str String to encode
bool $skip_ascii Only ncrencode unicode bytes
bool $skip_win If true and $skip_ascii is true, it will skip windows-1252 extended chars

Return Value

string Encoded string

at line 773
static string ncrencodeMatches($matches, $skip_ascii = false, $skip_win = false)

NCR encodes matches from a preg_replace.

Single byte characters are preserved.

Parameters

$matches
$skip_ascii
$skip_win

Return Value

string The encoded character

at line 798
static int ordUni(string $chr)

Gets the Unicode Ordinal for a UTF-8 character.

Parameters

string $chr Character to convert

Return Value

int Ordinal value or false if invalid

at line 860
static mixed parseUrl(string $url, int $component = -1)

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

Parameters

string $url
int $component

Return Value

mixed

at line 925
static jsonEncodeLocalCharset($value, $options = 0, $depth = 512)

Parameters

$value
$options
$depth

at line 950
static string encodeUtf8Url(string $url)

Encode a UTF-8 Encoded URL and urlencode it while leaving control characters in tact.

(It can also work with single byte encodings, but its purpose is to supply UTF-8 urls on non UTF-8 forums.)

Parameters

string $url url

Return Value

string

at line 1005
static decodeUtf8Url($url)

Parameters

$url

at line 1040
static string fetchCensoredText(string $text)

Replaces any instances of words censored in $options['censorwords'] with $options['censorchar']

Parameters

string $text Text to be censored

Return Value

string

at line 1104
static string fetchTrimmedTitle(string $title, integer $chars, boolean $append = true)

Trims a string to the specified length while keeping whole words.

Parameters

string $title String to be trimmed.
integer $chars Number of characters to aim for in the trimmed string. If 0 then return the title unchanged.
boolean $append Append "..." to shortened text.

Return Value

string Trimmed string.

at line 1142
static isVbCharset($charset)

Parameters

$charset

at line 1147
static areCharsetsEqual($charset1, $charset2)

Parameters

$charset1
$charset2

at line 1173
static string stripBbcode(string $message, boolean $stripquotes = false, boolean $fast_and_dirty = false, boolean $showlinks = true, boolean $stripimg = false, boolean $keepquotetags = false)

Strips away bbcode from a given string, leaving plain text

Parameters

string $message Text to be stripped of bbcode tags
boolean $stripquotes If true, strip away quote tags AND their contents
boolean $fast_and_dirty If true, use the fast-and-dirty method rather than the shiny and nice method
boolean $showlinks If true, display the url of the link in parenthesis after the link text
boolean $stripimg If true, strip away img/video tags and their contents
boolean $keepquotetags If true, keep [quote] tags. Useful for API.

Return Value

string