JString
String handling class for utf-8 data Wraps the phputf8 library All functions assume the validity of utf-8 strings.
package |
Joomla.Platform |
---|---|
subpackage |
String |
since |
11.1 |
Methods
_iconvErrorHandler
Catch an error and throw an exception.
_iconvErrorHandler(integer $number, string $message) : void
link | |
---|---|
throw |
Arguments
- $number
integer
Error level- $message
string
Error message
compliant
Tests whether a string complies as UTF-8. This will be much faster than utf8_is_valid but will pass five and six octet UTF-8 sequences, which are not supported by Unicode and so cannot be displayed correctly in a browser. In other words it is not as strict as utf8_is_valid but it's faster. If you use it to validate user input, you place yourself at the risk that attackers will be able to inject 5 and 6 byte sequences (which may or may not be a significant risk, depending on what you are are doing)
compliant(string $str) : boolean
see |
\valid
http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805 |
---|---|
since |
11.1 |
Arguments
- $str
string
UTF-8 string to check
Response
boolean
TRUE if string is valid UTF-8
increment
Increments a trailing number in a string.
increment(string $string, string $style = 'default', integer $n) : string
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"
since |
11.3 |
---|
Arguments
- $string
string
The source string.- $style
string
The the style (default|dash).- $n
integer
If supplied, this number is used for the copy, otherwise it is the 'next' number.
Response
string
The incremented string.
ltrim
UTF-8 aware replacement for ltrim()
ltrim(string $str, string $charlist = false) : string
Strip whitespace (or other characters) from the beginning of a string You only need to use this if you are supplying the charlist optional arg and it contains UTF-8 characters. Otherwise ltrim will work normally on a UTF-8 string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The string to be trimmed- $charlist
string
The optional charlist of additional characters to trim
Response
string
The trimmed string
parse_url
Does a UTF-8 safe version of PHP parse_url function
parse_url(string $url) : mixed
see | |
---|---|
since |
11.1 |
Arguments
- $url
string
URL to parse
Response
mixed
Associative array or false if badly formed URL.
rtrim
UTF-8 aware replacement for rtrim() Strip whitespace (or other characters) from the end of a string You only need to use this if you are supplying the charlist optional arg and it contains UTF-8 characters. Otherwise rtrim will work normally on a UTF-8 string
rtrim(string $str, string $charlist = false) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The string to be trimmed- $charlist
string
The optional charlist of additional characters to trim
Response
string
The trimmed string
splitCamelCase
Split a string in camel case format
splitCamelCase(string $string) : array
"FooBarABCDef" becomes array("Foo", "Bar", "ABC", "Def"); "JFooBar" becomes array("J", "Foo", "Bar"); "J001FooBar002" becomes array("J001", "Foo", "Bar002"); "abcDef" becomes array("abc", "Def"); "abc_defGhi_Jkl" becomes array("abc_def", "Ghi_Jkl"); "ThisIsA_NASAAstronaut" becomes array("This", "Is", "A_NASA", "Astronaut")), "JohnFitzgerald_Kennedy" becomes array("John", "Fitzgerald_Kennedy")),
since |
11.3 |
---|
Arguments
- $string
string
The source string.
Response
array
The splitted string.
str_ireplace
UTF-8 aware alternative to str_ireplace Case-insensitive version of str_replace
str_ireplace(string $search, string $replace, string $str, integer $count = null) : string
see | |
---|---|
since |
11.1 |
Arguments
- $search
string
String to search- $replace
string
Existing string to replace- $str
string
New string to replace with- $count
integer
Optional count value to be passed by referene
Response
string
UTF-8 String
str_split
UTF-8 aware alternative to str_split Convert a string to an array
str_split(string $str, integer $split_len = 1) : array
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
UTF-8 encoded string to process- $split_len
integer
Number to characters to split string by
Response
array
strcasecmp
UTF-8/LOCALE aware alternative to strcasecmp A case insensitive string comparison
strcasecmp(string $str1, string $str2, mixed $locale = false) : integer
see | |
---|---|
since |
11.1 |
Arguments
- $str1
string
string 1 to compare- $str2
string
string 2 to compare- $locale
mixed
The locale used by strcoll or false to use classical comparison
Response
integer
< 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
strcmp
UTF-8/LOCALE aware alternative to strcmp A case sensitive string comparison
strcmp(string $str1, string $str2, mixed $locale = false) : integer
see | |
---|---|
since |
11.1 |
Arguments
- $str1
string
string 1 to compare- $str2
string
string 2 to compare- $locale
mixed
The locale used by strcoll or false to use classical comparison
Response
integer
< 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.
strcspn
UTF-8 aware alternative to strcspn Find length of initial segment not matching mask
strcspn(string $str, string $mask, integer $start = null, integer $length = null) : integer
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The string to process- $mask
string
The mask- $start
integer
Optional starting character position (in characters)- $length
integer
Optional length
Response
integer
The length of the initial segment of str1 which does not contain any of the characters in str2
stristr
UTF-8 aware alternative to stristr Returns all of haystack from the first occurrence of needle to the end.
stristr(string $str, string $search) : string
needle and haystack are examined in a case-insensitive manner Find first occurrence of a string using case insensitive comparison
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The haystack- $search
string
The needle
Response
string
the sub string
strlen
UTF-8 aware alternative to strlen.
strlen(string $str) : integer
Returns the number of characters in the string (NOT THE NUMBER OF BYTES),
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
UTF-8 string.
Response
integer
Number of UTF-8 characters in string.
strpos
UTF-8 aware alternative to strpos.
strpos(string $str, string $search, integer $offset = false) : mixed
Find position of first occurrence of a string.
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String being examined- $search
string
String being searched for- $offset
integer
Optional, specifies the position from which the search should be performed
Response
mixed
Number of characters before the first match or FALSE on failure
strrev
UTF-8 aware alternative to strrev Reverse a string
strrev(string $str) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String to be reversed
Response
string
The string in reverse character order
strrpos
UTF-8 aware alternative to strrpos Finds position of last occurrence of a string
strrpos(string $str, string $search, integer $offset) : mixed
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String being examined.- $search
string
String being searched for.- $offset
integer
Offset from the left of the string.
Response
mixed
Number of characters before the last match or false on failure
strspn
UTF-8 aware alternative to strspn Find length of initial segment matching mask
strspn(string $str, string $mask, integer $start = null, integer $length = null) : integer
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The haystack- $mask
string
The mask- $start
integer
Start optional- $length
integer
Length optional
Response
integer
strtolower
UTF-8 aware alternative to strtlower
strtolower(string $str) : mixed
Make a string lowercase Note: The concept of a characters "case" only exists is some alphabets such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does not exist in the Chinese alphabet, for example. See Unicode Standard Annex #21: Case Mappings
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String being processed
Response
mixed
Either string in lowercase or FALSE is UTF-8 invalid
strtoupper
UTF-8 aware alternative to strtoupper Make a string uppercase Note: The concept of a characters "case" only exists is some alphabets such as Latin, Greek, Cyrillic, Armenian and archaic Georgian - it does not exist in the Chinese alphabet, for example. See Unicode Standard Annex #21: Case Mappings
strtoupper(string $str) : mixed
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String being processed
Response
mixed
Either string in uppercase or FALSE is UTF-8 invalid
substr
UTF-8 aware alternative to substr Return part of a string given character offset (and optionally length)
substr(string $str, integer $offset, integer $length = false) : mixed
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String being processed- $offset
integer
Number of UTF-8 characters offset (from left)- $length
integer
Optional length in UTF-8 characters from offset
Response
mixed
string or FALSE if failure
substr_replace
UTF-8 aware substr_replace Replace text within a portion of a string
substr_replace(string $str, string $repl, integer $start, integer $length = null) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The haystack- $repl
string
The replacement string- $start
integer
Start- $length
integer
Length (optional)
Response
string
transcode
Transcode a string.
transcode(string $source, string $from_encoding, string $to_encoding) : mixed
link | |
---|---|
since |
11.1 |
Arguments
- $source
string
The string to transcode.- $from_encoding
string
The source encoding.- $to_encoding
string
The target encoding.
Response
mixed
The transcoded string, or null if the source was not a string.
trim
UTF-8 aware replacement for trim() Strip whitespace (or other characters) from the beginning and end of a string Note: you only need to use this if you are supplying the charlist optional arg and it contains UTF-8 characters. Otherwise trim will work normally on a UTF-8 string
trim(string $str, string $charlist = false) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
The string to be trimmed- $charlist
string
The optional charlist of additional characters to trim
Response
string
The trimmed string
ucfirst
UTF-8 aware alternative to ucfirst Make a string's first character uppercase or all words' first character uppercase
ucfirst(string $str, string $delimiter = null, string $newDelimiter = null) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String to be processed- $delimiter
string
The words delimiter (null means do not split the string)- $newDelimiter
string
The new words delimiter (null means equal to $delimiter)
Response
string
If $delimiter is null, return the string with first character as upper case (if applicable)
else consider the string of words separated by the delimiter, apply the ucfirst to each words
and return the string with the new delimiter
ucwords
UTF-8 aware alternative to ucwords Uppercase the first character of each word in a string
ucwords(string $str) : string
see | |
---|---|
since |
11.1 |
Arguments
- $str
string
String to be processed
Response
string
String with first char of each word uppercase
valid
Tests a string as to whether it's valid UTF-8 and supported by the Unicode standard.
valid(string $str) : boolean
Note: this function has been modified to simple return true or false.
author | |
---|---|
see | \compliant |
since |
11.1 |
Arguments
- $str
string
UTF-8 encoded string.
Response
boolean
true if valid
Properties
incrementStyles
Increment styles.
since |
11.3 |
---|
Type(s)
array