[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/string/src/ -> StringHelper.php (summary)

Part of the Joomla Framework String Package

Copyright: Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
License: GNU General Public License version 2 or later; see LICENSE
File Size: 814 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 29 functions

  increment()
  is_ascii()
  ord()
  strpos()
  strrpos()
  substr()
  strtolower()
  strtoupper()
  strlen()
  str_ireplace()
  str_pad()
  str_split()
  strcasecmp()
  strcmp()
  strcspn()
  stristr()
  strrev()
  strspn()
  substr_replace()
  ltrim()
  rtrim()
  trim()
  ucfirst()
  ucwords()
  transcode()
  valid()
  compliant()
  unicode_to_utf8()
  unicode_to_utf16()

Functions
Functions that are not part of a class:

increment($string, $style = 'default', $n = 0)   X-Ref
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: string       $string  The source string.
param: string|null  $style   The the style (default|dash).
param: integer      $n       If supplied, this number is used for the copy, otherwise it is the 'next' number.
return: string  The incremented string.

is_ascii($str)   X-Ref
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.;

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

param: string  $str  The string to test.
return: boolean True if the string is all ASCII

ord($chr)   X-Ref
UTF-8 aware alternative to ord()

Returns the unicode ordinal for a character.

param: string  $chr  UTF-8 encoded character
return: integer Unicode ordinal for the character

strpos($str, $search, $offset = false)   X-Ref
UTF-8 aware alternative to strpos()

Find position of first occurrence of a string.

param: string                $str     String being examined
param: string                $search  String being searched for
param: integer|null|boolean  $offset  Optional, specifies the position from which the search should be performed
return: integer|boolean  Number of characters before the first match or FALSE on failure

strrpos($str, $search, $offset = 0)   X-Ref
UTF-8 aware alternative to strrpos()

Finds position of last occurrence of a string.

param: string   $str     String being examined.
param: string   $search  String being searched for.
param: integer  $offset  Offset from the left of the string.
return: integer|boolean  Number of characters before the last match or false on failure

substr($str, $offset, $length = false)   X-Ref
UTF-8 aware alternative to substr()

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

param: string                $str     String being processed
param: integer               $offset  Number of UTF-8 characters offset (from left)
param: integer|null|boolean  $length  Optional length in UTF-8 characters from offset
return: string|boolean

strtolower($str)   X-Ref
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: string  $str  String being processed
return: string|boolean  Either string in lowercase or FALSE is UTF-8 invalid

strtoupper($str)   X-Ref
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: string  $str  String being processed
return: string|boolean  Either string in uppercase or FALSE is UTF-8 invalid

strlen($str)   X-Ref
UTF-8 aware alternative to strlen()

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

param: string  $str  UTF-8 string.
return: integer  Number of UTF-8 characters in string.

str_ireplace($search, $replace, $str, $count = null)   X-Ref
UTF-8 aware alternative to str_ireplace()

Case-insensitive version of str_replace()

param: string                $search   String to search
param: string                $replace  Existing string to replace
param: string                $str      New string to replace with
param: integer|null|boolean  $count    Optional count value to be passed by referene
return: string  UTF-8 String

str_pad($input, $length, $padStr = ' ', $type = STR_PAD_RIGHT)   X-Ref
UTF-8 aware alternative to str_pad()

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

param: string   $input   The input string.
param: integer  $length  If the value is negative, less than, or equal to the length of the input string, no padding takes place.
param: string   $padStr  The string may be truncated if the number of padding characters can't be evenly divided by the string's length.
param: integer  $type    The type of padding to apply
return: string

str_split($str, $splitLen = 1)   X-Ref
UTF-8 aware alternative to str_split()

Convert a string to an array.

param: string   $str       UTF-8 encoded string to process
param: integer  $splitLen  Number to characters to split string by
return: array|string|boolean

strcasecmp($str1, $str2, $locale = false)   X-Ref
UTF-8/LOCALE aware alternative to strcasecmp()

A case insensitive string comparison.

param: string          $str1    string 1 to compare
param: string          $str2    string 2 to compare
param: string|boolean  $locale  The locale used by strcoll or false to use classical comparison
return: integer   < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

strcmp($str1, $str2, $locale = false)   X-Ref
UTF-8/LOCALE aware alternative to strcmp()

A case sensitive string comparison.

param: string  $str1    string 1 to compare
param: string  $str2    string 2 to compare
param: mixed   $locale  The locale used by strcoll or false to use classical comparison
return: integer  < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

strcspn($str, $mask, $start = null, $length = null)   X-Ref
UTF-8 aware alternative to strcspn()

Find length of initial segment not matching mask.

param: string           $str     The string to process
param: string           $mask    The mask
param: integer|boolean  $start   Optional starting character position (in characters)
param: integer|boolean  $length  Optional length
return: integer  The length of the initial segment of str1 which does not contain any of the characters in str2

stristr($str, $search)   X-Ref
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: string  $str     The haystack
param: string  $search  The needle
return: string|boolean

strrev($str)   X-Ref
UTF-8 aware alternative to strrev()

Reverse a string.

param: string  $str  String to be reversed
return: string   The string in reverse character order

strspn($str, $mask, $start = null, $length = null)   X-Ref
UTF-8 aware alternative to strspn()

Find length of initial segment matching mask.

param: string        $str     The haystack
param: string        $mask    The mask
param: integer|null  $start   Start optional
param: integer|null  $length  Length optional
return: integer

substr_replace($str, $repl, $start, $length = null)   X-Ref
UTF-8 aware alternative to substr_replace()

Replace text within a portion of a string.

param: string                $str     The haystack
param: string                $repl    The replacement string
param: integer               $start   Start
param: integer|boolean|null  $length  Length (optional)
return: string

ltrim($str, $charlist = false)   X-Ref
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: string          $str       The string to be trimmed
param: string|boolean  $charlist  The optional charlist of additional characters to trim
return: string  The trimmed string

rtrim($str, $charlist = false)   X-Ref
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: string          $str       The string to be trimmed
param: string|boolean  $charlist  The optional charlist of additional characters to trim
return: string  The trimmed string

trim($str, $charlist = false)   X-Ref
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: string          $str       The string to be trimmed
param: string|boolean  $charlist  The optional charlist of additional characters to trim
return: string  The trimmed string

ucfirst($str, $delimiter = null, $newDelimiter = null)   X-Ref
UTF-8 aware alternative to ucfirst()

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

param: string       $str           String to be processed
param: string|null  $delimiter     The words delimiter (null means do not split the string)
param: string|null  $newDelimiter  The new words delimiter (null means equal to $delimiter)
return: string  If $delimiter is null, return the string with first character as upper case (if applicable)

ucwords($str)   X-Ref
UTF-8 aware alternative to ucwords()

Uppercase the first character of each word in a string.

param: string  $str  String to be processed
return: string  String with first char of each word uppercase

transcode($source, $fromEncoding, $toEncoding)   X-Ref
Transcode a string.

param: string  $source        The string to transcode.
param: string  $fromEncoding  The source encoding.
param: string  $toEncoding    The target encoding.
return: string|null  The transcoded string, or null if the source was not a string.

valid($str)   X-Ref
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.

author: <[email protected]>
param: string  $str  UTF-8 encoded string.
return: boolean  true if valid

compliant($str)   X-Ref
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: string  $str  UTF-8 string to check
return: boolean  TRUE if string is valid UTF-8

unicode_to_utf8($str)   X-Ref
Converts Unicode sequences to UTF-8 string.

param: string  $str  Unicode string to convert
return: string  UTF-8 string

unicode_to_utf16($str)   X-Ref
No description



Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer