Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 925 lines (32 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Horde_String:: (26 methods):
  convertCharset()
  _convertCharset()
  lower()
  upper()
  ucfirst()
  ucwords()
  substr()
  length()
  pos()
  ipos()
  rpos()
  ripos()
  _pos()
  pad()
  wordwrap()
  wrap()
  truncate()
  abbreviate()
  common()
  isAlpha()
  isLower()
  isUpper()
  regexMatch()
  validUtf8()
  _mbstringCharset()
  trimUtf8Bom()


Class: Horde_String  - X-Ref

Provides static methods for charset and locale safe string manipulation.

Copyright 2003-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you
did not receive this file, see http://www.horde.org/licenses/lgpl21.

convertCharset($input, $from, $to, $force = false)   X-Ref
Converts a string from one charset to another.

Uses the iconv or the mbstring extensions.
The original string is returned if conversion failed or none
of the extensions were available.

param: mixed $input    The data to be converted. If $input is an an
param: string $from    The string's current charset.
param: string $to      The charset to convert the string to.
param: boolean $force  Force conversion?
return: mixed  The converted input data.

_convertCharset($input, $from, $to)   X-Ref
Internal function used to do charset conversion.

param: string $input  See self::convertCharset().
param: string $from   See self::convertCharset().
param: string $to     See self::convertCharset().
return: string  The converted string.

lower($string, $locale = false, $charset = null)   X-Ref
Makes a string lowercase.

param: string $string   The string to be converted.
param: boolean $locale  If true the string will be converted based on
param: string $charset  If $locale is true, the charset to use when
return: string  The string with lowercase characters.

upper($string, $locale = false, $charset = null)   X-Ref
Makes a string uppercase.

param: string $string   The string to be converted.
param: boolean $locale  If true the string will be converted based on a
param: string $charset  If $locale is true, the charset to use when
return: string  The string with uppercase characters.

ucfirst($string, $locale = false, $charset = null)   X-Ref
Returns a string with the first letter capitalized if it is
alphabetic.

param: string $string   The string to be capitalized.
param: boolean $locale  If true the string will be converted based on a
param: string $charset  The charset to use, defaults to current charset.
return: string  The capitalized string.

ucwords($string, $locale = false, $charset = null)   X-Ref
Returns a string with the first letter of each word capitalized if it is
alphabetic.

Sentences are splitted into words at whitestrings.

param: string $string   The string to be capitalized.
param: boolean $locale  If true the string will be converted based on a
param: string $charset  The charset to use, defaults to current charset.
return: string  The capitalized string.

substr($string, $start, $length = null,$charset = 'UTF-8')   X-Ref
Returns part of a string.

param: string $string   The string to be converted.
param: integer $start   The part's start position, zero based.
param: integer $length  The part's length.
param: string $charset  The charset to use when calculating the part's
return: string  The string's part.

length($string, $charset = 'UTF-8')   X-Ref
Returns the character (not byte) length of a string.

param: string $string  The string to return the length of.
param: string $charset The charset to use when calculating the string's
return: integer  The string's length.

pos($haystack, $needle, $offset = 0, $charset = 'UTF-8')   X-Ref
Returns the numeric position of the first occurrence of $needle
in the $haystack string.

param: string $haystack  The string to search through.
param: string $needle    The string to search for.
param: integer $offset   Character in $haystack to start searching at.
param: string $charset   Charset of $needle.
return: integer  The position of first occurrence.

ipos($haystack, $needle, $offset = 0, $charset = 'UTF-8')   X-Ref
Returns the numeric position of the first case-insensitive occurrence
of $needle in the $haystack string.

param: string $haystack  The string to search through.
param: string $needle    The string to search for.
param: integer $offset   Character in $haystack to start searching at.
param: string $charset   Charset of $needle.
return: integer  The position of first case-insensitive occurrence.

rpos($haystack, $needle, $offset = 0, $charset = 'UTF-8')   X-Ref
Returns the numeric position of the last occurrence of $needle
in the $haystack string.

param: string $haystack  The string to search through.
param: string $needle    The string to search for.
param: integer $offset   Character in $haystack to start searching at.
param: string $charset   Charset of $needle.
return: integer  The position of last occurrence.

ripos($haystack, $needle, $offset = 0, $charset = 'UTF-8')   X-Ref
Returns the numeric position of the last case-insensitive occurrence of
$needle in the $haystack string.

param: string $haystack  The string to search through.
param: string $needle    The string to search for.
param: integer $offset   Character in $haystack to start searching at.
param: string $charset   Charset of $needle.
return: integer  The position of last case-insensitive occurrence.

_pos($haystack, $needle, $offset, $charset, $func)   X-Ref
Perform string position searches.

param: string $haystack  The string to search through.
param: string $needle    The string to search for.
param: integer $offset   Character in $haystack to start searching at.
param: string $charset   Charset of $needle.
param: string $func      Function to use.
return: integer  The position of occurrence.

pad($input, $length, $pad = ' ',$type = STR_PAD_RIGHT, $charset = 'UTF-8')   X-Ref
Returns a string padded to a certain length with another string.
This method behaves exactly like str_pad() but is multibyte safe.

param: string $input    The string to be padded.
param: integer $length  The length of the resulting string.
param: string $pad      The string to pad the input string with. Must
param: const $type      The padding type. One of STR_PAD_LEFT,
param: string $charset  The charset of the input and the padding
return: string  The padded string.

wordwrap($string, $width = 75, $break = "\n",$cut = false, $line_folding = false)   X-Ref
Wraps the text of a message.

param: string $string         String containing the text to wrap.
param: integer $width         Wrap the string at this number of
param: string $break          Character(s) to use when breaking lines.
param: boolean $cut           Whether to cut inside words if a line
param: boolean $line_folding  Whether to apply line folding rules per
return: string  String containing the wrapped text.

wrap($text, $length = 80, $break_char = "\n",$quote = false)   X-Ref
Wraps the text of a message.

param: string $text        String containing the text to wrap.
param: integer $length     Wrap $text at this number of characters.
param: string $break_char  Character(s) to use when breaking lines.
param: boolean $quote      Ignore lines that are wrapped with the '>'
return: string  String containing the wrapped text.

truncate($text, $length = 100)   X-Ref
Return a truncated string, suitable for notifications.

param: string $text     The original string.
param: integer $length  The maximum length.
return: string  The truncated string, if longer than $length.

abbreviate($text, $length = 20)   X-Ref
Return an abbreviated string, with characters in the middle of the
excessively long string replaced by '...'.

param: string $text     The original string.
param: integer $length  The length at which to abbreviate.
return: string  The abbreviated string, if longer than $length.

common($str1, $str2)   X-Ref
Returns the common leading part of two strings.

param: string $str1  A string.
param: string $str2  Another string.
return: string  The start of $str1 and $str2 that is identical in both.

isAlpha($string, $charset)   X-Ref
Returns true if the every character in the parameter is an alphabetic
character.

param: string $string   The string to test.
param: string $charset  The charset to use when testing the string.
return: boolean  True if the parameter was alphabetic only.

isLower($string, $charset)   X-Ref
Returns true if ever character in the parameter is a lowercase letter in
the current locale.

param: string $string   The string to test.
param: string $charset  The charset to use when testing the string.
return: boolean  True if the parameter was lowercase.

isUpper($string, $charset)   X-Ref
Returns true if every character in the parameter is an uppercase letter
in the current locale.

param: string $string   The string to test.
param: string $charset  The charset to use when testing the string.
return: boolean  True if the parameter was uppercase.

regexMatch($text, $regex, $charset = null)   X-Ref
Performs a multibyte safe regex match search on the text provided.

param: string $text     The text to search.
param: array $regex     The regular expressions to use, without perl
param: string $charset  The character set of the text.
return: array  The matches array from the first regex that matches.

validUtf8($text)   X-Ref
Check to see if a string is valid UTF-8.

param: string $text  The text to check.
return: boolean  True if valid UTF-8.

_mbstringCharset($charset)   X-Ref
Workaround charsets that don't work with mbstring functions.

param: string $charset  The original charset.
return: string  The charset to use with mbstring functions.

trimUtf8Bom($str)   X-Ref
Strip UTF-8 byte order mark (BOM) from string data.

param: string $str  Input string (UTF-8).
return: string  Stripped string (UTF-8).