Joomla CMS  4.2.2
Documentation des API du CMS Joomla en version 4.2.2
Référence de la classe StringHelper

Fonctions membres publiques statiques

static static increment ($string, $style='default', $n=0)
 
static is_ascii ($str)
 
static ord ($chr)
 
static strpos ($str, $search, $offset=false)
 
static strrpos ($str, $search, $offset=0)
 
static substr ($str, $offset, $length=false)
 
static strtolower ($str)
 
static strtoupper ($str)
 
static strlen ($str)
 
static str_ireplace ($search, $replace, $str, $count=null)
 
static str_pad ($input, $length, $padStr=' ', $type=STR_PAD_RIGHT)
 
static str_split ($str, $splitLen=1)
 
static strcasecmp ($str1, $str2, $locale=false)
 
static strcmp ($str1, $str2, $locale=false)
 
static strcspn ($str, $mask, $start=null, $length=null)
 
static stristr ($str, $search)
 
static strrev ($str)
 
static strspn ($str, $mask, $start=null, $length=null)
 
static substr_replace ($str, $repl, $start, $length=null)
 
static ltrim ($str, $charlist=false)
 
static rtrim ($str, $charlist=false)
 
static trim ($str, $charlist=false)
 
static ucfirst ($str, $delimiter=null, $newDelimiter=null)
 
static ucwords ($str)
 
static transcode ($source, $fromEncoding, $toEncoding)
 
static valid ($str)
 
static compliant ($str)
 
static unicode_to_utf8 ($str)
 
static unicode_to_utf16 ($str)
 

Attributs protégés statiques

static $incrementStyles
 

Description détaillée

String handling class for UTF-8 data wrapping the phputf8 library. All functions assume the validity of UTF-8 strings.

Depuis
1.3.0

Documentation des fonctions membres

◆ compliant()

static compliant (   $str)
static

Tests whether a string complies as UTF-8.

This will be much faster than StringHelper::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 StringHelper::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).

Paramètres
string$strUTF-8 string to check
Renvoie
boolean TRUE if string is valid UTF-8
Voir également
StringHelper::valid 1.3.0

Références utf8_compliant().

◆ increment()

static static increment (   $string,
  $style = 'default',
  $n = 0 
)
static

Increments a trailing number in a 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"

Paramètres
string$stringThe source string.
string | null$styleThe the style (default|dash).
integer$nIf supplied, this number is used for the copy, otherwise it is the 'next' number.
Renvoie
string The incremented string.
Depuis
1.3.0

Références $n, et $style.

Référencé par FieldTable\check(), GroupModel\generateGroupTitle(), StageModel\generateNewTitle(), WorkflowModel\generateNewTitle(), TransitionModel\generateNewTitle(), StyleModel\generateNewTitle(), FieldModel\generateNewTitle(), ModuleModel\generateNewTitle(), AdminModel\generateNewTitle(), CategoryModel\generateNewTitle(), ItemModel\generateNewTitle(), et ModuleModel\save().

◆ is_ascii()

static is_ascii (   $str)
static

Tests whether a string contains only 7bit ASCII bytes.

You might use this to conditionally check whether a string needs handling as UTF-8 or not, potentially offering performance benefits by using the native PHP equivalent if it's just ASCII e.g.;

if (StringHelper::is_ascii($someString)) { // It's just ASCII - use the native PHP version $someString = strtolower($someString); } else { $someString = StringHelper::strtolower($someString); }

Paramètres
string$strThe string to test.
Renvoie
boolean True if the string is all ASCII
Depuis
1.3.0

Références utf8_is_ascii().

◆ ltrim()

static ltrim (   $str,
  $charlist = false 
)
static

UTF-8 aware replacement for ltrim()

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.

Paramètres
string$strThe string to be trimmed
string | boolean$charlistThe optional charlist of additional characters to trim
Renvoie
string The trimmed string

1.3.0

Références utf8_ltrim().

◆ ord()

static ord (   $chr)
static

UTF-8 aware alternative to ord()

Returns the unicode ordinal for a character.

Paramètres
string$chrUTF-8 encoded character
Renvoie
integer Unicode ordinal for the character

1.4.0

Références utf8_ord().

Référencé par OutputFilter\stringJSSafe().

◆ rtrim()

static rtrim (   $str,
  $charlist = false 
)
static

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.

Paramètres
string$strThe string to be trimmed
string | boolean$charlistThe optional charlist of additional characters to trim
Renvoie
string The trimmed string

1.3.0

Références utf8_rtrim().

◆ str_ireplace()

static str_ireplace (   $search,
  $replace,
  $str,
  $count = null 
)
static

UTF-8 aware alternative to str_ireplace()

Case-insensitive version of str_replace()

Paramètres
string$searchString to search
string$replaceExisting string to replace
string$strNew string to replace with
integer | null | boolean$countOptional count value to be passed by referene
Renvoie
string UTF-8 String

1.3.0

Références $count, et utf8_ireplace().

Référencé par TagTable\check(), NewsfeedTable\check(), CoreContent\check(), ContactTable\check(), Content\check(), et Zh\tokenise().

◆ str_pad()

static str_pad (   $input,
  $length,
  $padStr = ' ',
  $type = STR_PAD_RIGHT 
)
static

UTF-8 aware alternative to str_pad()

Pad a string to a certain length with another string. $padStr may contain multi-byte characters.

Paramètres
string$inputThe input string.
integer$lengthIf the value is negative, less than, or equal to the length of the input string, no padding takes place.
string$padStrThe string may be truncated if the number of padding characters can't be evenly divided by the string's length.
integer$typeThe type of padding to apply
Renvoie
string

1.4.0

Références $input, $type, et utf8_str_pad().

◆ str_split()

static str_split (   $str,
  $splitLen = 1 
)
static

UTF-8 aware alternative to str_split()

Convert a string to an array.

Paramètres
string$strUTF-8 encoded string to process
integer$splitLenNumber to characters to split string by
Renvoie
array|string|boolean

1.3.0

Références utf8_str_split().

◆ strcasecmp()

static strcasecmp (   $str1,
  $str2,
  $locale = false 
)
static

UTF-8/LOCALE aware alternative to strcasecmp()

A case insensitive string comparison.

Paramètres
string$str1string 1 to compare
string$str2string 2 to compare
string | boolean$localeThe locale used by strcoll or false to use classical comparison
Renvoie
integer < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

https://www.php.net/strcoll https://www.php.net/setlocale 1.3.0

Références elseif, StringHelper\stristr(), utf8_strcasecmp(), et utf8_strtolower().

Référencé par ArrayHelper\sortObjects().

◆ strcmp()

static strcmp (   $str1,
  $str2,
  $locale = false 
)
static

UTF-8/LOCALE aware alternative to strcmp()

A case sensitive string comparison.

Paramètres
string$str1string 1 to compare
string$str2string 2 to compare
mixed$localeThe locale used by strcoll or false to use classical comparison
Renvoie
integer < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

https://www.php.net/strcoll https://www.php.net/setlocale 1.3.0

Références elseif, et StringHelper\stristr().

Référencé par LanguagesModel\getLanguages(), et ArrayHelper\sortObjects().

◆ strcspn()

static strcspn (   $str,
  $mask,
  $start = null,
  $length = null 
)
static

UTF-8 aware alternative to strcspn()

Find length of initial segment not matching mask.

Paramètres
string$strThe string to process
string$maskThe mask
integer | boolean$startOptional starting character position (in characters)
integer | boolean$lengthOptional length
Renvoie
integer The length of the initial segment of str1 which does not contain any of the characters in str2

1.3.0

Références $start, et utf8_strcspn().

◆ stristr()

static stristr (   $str,
  $search 
)
static

UTF-8 aware alternative to stristr()

Returns all of haystack from the first occurrence of needle to the end. Needle and haystack are examined in a case-insensitive manner to find the first occurrence of a string using case insensitive comparison.

Paramètres
string$strThe haystack
string$searchThe needle
Renvoie
string|boolean

1.3.0

Références utf8_stristr().

Référencé par StringHelper\strcasecmp(), StringHelper\strcmp(), ContactEmailRule\test(), ContactEmailSubjectRule\test(), et ContactEmailMessageRule\test().

◆ strlen()

static strlen (   $str)
static

UTF-8 aware alternative to strlen()

Returns the number of characters in the string (NOT THE NUMBER OF BYTES).

Paramètres
string$strUTF-8 string.
Renvoie
integer Number of UTF-8 characters in string.

1.3.0

Références utf8_strlen().

Référencé par Token\__construct(), User\check(), InputFilter\cleanTags(), TextDescriptor\describeJoomlaApplication(), Application\doRenderThrowable(), InputFilter\escapeAttributeValues(), TextDescriptor\getColumnWidth(), et Query\processString().

◆ strpos()

static strpos (   $str,
  $search,
  $offset = false 
)
static

UTF-8 aware alternative to strpos()

Find position of first occurrence of a string.

Paramètres
string$strString being examined
string$searchString being searched for
integer | null | boolean$offsetOptional, specifies the position from which the search should be performed
Renvoie
integer|boolean Number of characters before the first match or FALSE on failure

1.3.0

Références Joomla\Database\Query\$offset, et utf8_strpos().

Référencé par InputFilter\cleanTags(), RandomImageHelper\getFolder(), ActionlogsHelper\getHumanReadableLogMessage(), Helper\getPrimaryLanguage(), HelpModel\getToc(), et Query\processString().

◆ strrev()

static strrev (   $str)
static

UTF-8 aware alternative to strrev()

Reverse a string.

Paramètres
string$strString to be reversed
Renvoie
string The string in reverse character order

1.3.0

Références utf8_strrev().

◆ strrpos()

static strrpos (   $str,
  $search,
  $offset = 0 
)
static

UTF-8 aware alternative to strrpos()

Finds position of last occurrence of a string.

Paramètres
string$strString being examined.
string$searchString being searched for.
integer$offsetOffset from the left of the string.
Renvoie
integer|boolean Number of characters before the last match or false on failure

1.3.0

Références Joomla\Database\Query\$offset, et utf8_strrpos().

◆ strspn()

static strspn (   $str,
  $mask,
  $start = null,
  $length = null 
)
static

UTF-8 aware alternative to strspn()

Find length of initial segment matching mask.

Paramètres
string$strThe haystack
string$maskThe mask
integer | null$startStart optional
integer | null$lengthLength optional
Renvoie
integer

1.3.0

Références $start, null, et utf8_strspn().

◆ strtolower()

static strtolower (   $str)
static

UTF-8 aware alternative to strtolower()

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

Paramètres
string$strString being processed
Renvoie
string|boolean Either string in lowercase or FALSE is UTF-8 invalid

1.3.0

Références utf8_strtolower().

Référencé par SuggestionsModel\getListQuery(), TracksModel\getListQuery(), StylesModel\getListQuery(), TemplatesModel\getListQuery(), ModulesModel\getListQuery(), HelpModel\getToc(), SearchModel\populateState(), Query\processDates(), Query\processString(), SiteApplication\route(), CMSApplication\route(), OutputFilter\stringURLSafe(), OutputFilter\stringUrlSafe(), OutputFilter\stringUrlUnicodeSlug(), Language\tokenise(), et Language\transliterate().

◆ strtoupper()

static strtoupper (   $str)
static

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

Paramètres
string$strString being processed
Renvoie
string|boolean Either string in uppercase or FALSE is UTF-8 invalid

1.3.0

Références utf8_strtoupper().

◆ substr()

static substr (   $str,
  $offset,
  $length = false 
)
static

UTF-8 aware alternative to substr()

Return part of a string given character offset (and optionally length).

Paramètres
string$strString being processed
integer$offsetNumber of UTF-8 characters offset (from left)
integer | null | boolean$lengthOptional length in UTF-8 characters from offset
Renvoie
string|boolean

1.3.0

Références Joomla\Database\Query\$offset, et utf8_substr().

Référencé par InputFilter\cleanTags(), InputFilter\escapeAttributeValues(), Helper\getPrimaryLanguage(), ArticlesCategoryHelper\groupByDate(), Indexer\index(), et Query\processString().

◆ substr_replace()

static substr_replace (   $str,
  $repl,
  $start,
  $length = null 
)
static

UTF-8 aware alternative to substr_replace()

Replace text within a portion of a string.

Paramètres
string$strThe haystack
string$replThe replacement string
integer$startStart
integer | boolean | null$lengthLength (optional)
Renvoie
string

1.3.0

Références $start, et utf8_substr_replace().

◆ transcode()

static transcode (   $source,
  $fromEncoding,
  $toEncoding 
)
static

Transcode a string.

Paramètres
string$sourceThe string to transcode.
string$fromEncodingThe source encoding.
string$toEncodingThe target encoding.
Renvoie
string|null The transcoded string, or null if the source was not a string.

1.3.0

◆ trim()

static trim (   $str,
  $charlist = false 
)
static

UTF-8 aware replacement for trim()

Strip whitespace (or other characters) from the beginning and 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 trim will work normally on a UTF-8 string

Paramètres
string$strThe string to be trimmed
string | boolean$charlistThe optional charlist of additional characters to trim
Renvoie
string The trimmed string

1.3.0

Références utf8_trim().

Référencé par InputFilter\cleanTrim(), et Indexer\tokenizeToDb().

◆ ucfirst()

static ucfirst (   $str,
  $delimiter = null,
  $newDelimiter = null 
)
static

UTF-8 aware alternative to ucfirst()

Make a string's first character uppercase or all words' first character uppercase.

Paramètres
string$strString to be processed
string | null$delimiterThe words delimiter (null means do not split the string)
string | null$newDelimiterThe new words delimiter (null means equal to $delimiter)
Renvoie
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

1.3.0

Références null, et utf8_ucfirst().

Référencé par FormField\__construct(), et FormHelper\loadClass().

◆ ucwords()

static ucwords (   $str)
static

UTF-8 aware alternative to ucwords()

Uppercase the first character of each word in a string.

Paramètres
string$strString to be processed
Renvoie
string String with first char of each word uppercase

1.3.0

Références utf8_ucwords().

◆ unicode_to_utf16()

static unicode_to_utf16 (   $str)
static

Converts Unicode sequences to UTF-16 string.

Paramètres
string$strUnicode string to convert
Renvoie
string UTF-16 string
Depuis
1.3.0

◆ unicode_to_utf8()

static unicode_to_utf8 (   $str)
static

Converts Unicode sequences to UTF-8 string.

Paramètres
string$strUnicode string to convert
Renvoie
string UTF-8 string
Depuis
1.3.0

◆ valid()

static valid (   $str)
static

Tests a string as to whether it's valid UTF-8 and supported by the Unicode standard.

Note: this function has been modified to simple return true or false.

Paramètres
string$strUTF-8 encoded string.
Renvoie
boolean true if valid
Auteur
hsivo.nosp@m.nen@.nosp@m.iki.f.nosp@m.i compliant 1.3.0

Références utf8_is_valid().

Référencé par UrlRule\test().

Documentation des champs

◆ $incrementStyles

$incrementStyles
staticprotected
Valeur initiale :
= [
'dash' => [
'#-(\d+)$#',
'-%d',
]

La documentation de cette classe a été générée à partir du fichier suivant :