Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
core_text Class Reference

Static Public Member Functions

static code2utf8 ($num)
 Returns the utf8 string corresponding to the unicode value (from php.net, courtesy - roman.nosp@m.s@vo.nosp@m.id.lv) More...
 
static convert ($text, $fromCS, $toCS='utf-8')
 Converts the text between different encodings. More...
 
static encode_mimeheader ($text, $charset='utf-8')
 Generate a correct base64 encoded header to be used in MIME mail messages. More...
 
static entities_to_utf8 ($str, $htmlent=true)
 Converts all the numeric entities &#nnnn; or &#xnnn; to UTF-8 Original from laurynas dot butkus at gmail at: http://php.net/manual/en/function.html-entity-decode.php#75153 with some custom mods to provide more functionality. More...
 
static get_encodings ()
 Returns encoding options for select boxes, utf-8 and platform encoding first. More...
 
static parse_charset ($charset)
 Standardise charset name. More...
 
static remove_unicode_non_characters ($value)
 There are a number of Unicode non-characters including the byte-order mark (which may appear multiple times in a string) and also other ranges. More...
 
static reset_caches ()
 Reset internal textlib caches.
 
static specialtoascii ($text, $charset='utf-8')
 Try to convert upper unicode characters to plain ascii, the returned string may contain unconverted unicode characters. More...
 
static str_max_bytes ($string, $bytes)
 Truncates a string to no more than a certain number of bytes in a multi-byte safe manner. More...
 
static strlen ($text, $charset='utf-8')
 Multibyte safe strlen() function, uses mbstring or iconv for UTF-8, falls back to typo3. More...
 
static strpos ($haystack, $needle, $offset=0)
 Find the position of the first occurrence of a substring in a string. More...
 
static strrchr ($haystack, $needle, $part=false)
 Finds the last occurrence of a character in a string within another. More...
 
static strrev ($str)
 Reverse UTF-8 multibytes character sets (used for RTL languages) (We only do this because there is no mb_strrev or iconv_strrev) More...
 
static strrpos ($haystack, $needle)
 Find the position of the last occurrence of a substring in a string UTF-8 ONLY safe strrpos(), uses mbstring, falls back to iconv. More...
 
static strtolower ($text, $charset='utf-8')
 Multibyte safe strtolower() function, uses mbstring, falls back to typo3. More...
 
static strtotitle ($text)
 Makes first letter of each word capital - words must be separated by spaces. More...
 
static strtoupper ($text, $charset='utf-8')
 Multibyte safe strtoupper() function, uses mbstring, falls back to typo3. More...
 
static substr ($text, $start, $len=null, $charset='utf-8')
 Multibyte safe substr() function, uses mbstring or iconv for UTF-8, falls back to typo3. More...
 
static trim_utf8_bom ($str)
 Removes the BOM from unicode string More...
 
static utf8_to_entities ($str, $dec=false, $nonnum=false)
 Converts all Unicode chars > 127 to numeric entities &#nnnn; or &#xnnn;. More...
 
static utf8ord ($utf8char)
 Returns the code of the given UTF-8 character. More...
 

Static Protected Member Functions

static get_entities_table ()
 Returns HTML entity transliteration table. More...
 
static typo3 ($reset=false)
 Return t3lib helper class, which is used for conversion between charsets. More...
 

Static Protected Attributes

static string[] $noncharacters
 Array of strings representing Unicode non-characters.
 

Member Function Documentation

◆ code2utf8()

static core_text::code2utf8 (   $num)
static

Returns the utf8 string corresponding to the unicode value (from php.net, courtesy - roman.nosp@m.s@vo.nosp@m.id.lv)

Parameters
int$numone unicode value
Return values
stringthe UTF-8 char corresponding to the unicode value

◆ convert()

static core_text::convert (   $text,
  $fromCS,
  $toCS = 'utf-8' 
)
static

Converts the text between different encodings.

It uses iconv extension with //TRANSLIT parameter, falls back to typo3. If both source and target are utf-8 it tries to fix invalid characters only.

Parameters
string$text
string$fromCSsource encoding
string$toCSresult encoding
Return values
string|boolconverted string or false on error

◆ encode_mimeheader()

static core_text::encode_mimeheader (   $text,
  $charset = 'utf-8' 
)
static

Generate a correct base64 encoded header to be used in MIME mail messages.

This function seems to be 100% compliant with RFC1342. Credits go to: paravoid (http://www.php.net/manual/en/function.mb-encode-mimeheader.php#60283).

Parameters
string$textinput string
string$charsetencoding of the text
Return values
stringbase64 encoded header

◆ entities_to_utf8()

static core_text::entities_to_utf8 (   $str,
  $htmlent = true 
)
static

Converts all the numeric entities &#nnnn; or &#xnnn; to UTF-8 Original from laurynas dot butkus at gmail at: http://php.net/manual/en/function.html-entity-decode.php#75153 with some custom mods to provide more functionality.

Parameters
string$strinput string
boolean$htmlentconvert also html entities (defaults to true)
Return values
stringencoded UTF-8 string

◆ get_encodings()

static core_text::get_encodings ( )
static

Returns encoding options for select boxes, utf-8 and platform encoding first.

Return values
arrayencodings

◆ get_entities_table()

static core_text::get_entities_table ( )
staticprotected

Returns HTML entity transliteration table.

Return values
arraywith (html entity => utf-8) elements

◆ parse_charset()

static core_text::parse_charset (   $charset)
static

Standardise charset name.

Please note it does not mean the returned charset is actually supported.

Parameters
string$charsetraw charset name
Return values
stringnormalised lowercase charset name

◆ remove_unicode_non_characters()

static core_text::remove_unicode_non_characters (   $value)
static

There are a number of Unicode non-characters including the byte-order mark (which may appear multiple times in a string) and also other ranges.

These can cause problems for some processing.

This function removes the characters using string replace, so that the rest of the string remains unchanged.

Parameters
string$valueInput string
Return values
stringCleaned string value
Since
Moodle 3.5

◆ specialtoascii()

static core_text::specialtoascii (   $text,
  $charset = 'utf-8' 
)
static

Try to convert upper unicode characters to plain ascii, the returned string may contain unconverted unicode characters.

Parameters
string$textinput string
string$charsetencoding of the text
Return values
stringconverted ascii string

◆ str_max_bytes()

static core_text::str_max_bytes (   $string,
  $bytes 
)
static

Truncates a string to no more than a certain number of bytes in a multi-byte safe manner.

UTF-8 only!

Many of the other charsets we test for (like ISO-2022-JP and EUC-JP) are not supported by typo3, and will give invalid results, so we are supporting UTF-8 only.

Parameters
string$stringString to truncate
int$bytesMaximum length of bytes in the result
Return values
stringPortion of string specified by $bytes
Since
Moodle 3.1

◆ strlen()

static core_text::strlen (   $text,
  $charset = 'utf-8' 
)
static

Multibyte safe strlen() function, uses mbstring or iconv for UTF-8, falls back to typo3.

Parameters
string$textinput string
string$charsetencoding of the text
Return values
intnumber of characters

◆ strpos()

static core_text::strpos (   $haystack,
  $needle,
  $offset = 0 
)
static

Find the position of the first occurrence of a substring in a string.

UTF-8 ONLY safe strpos(), uses mbstring, falls back to iconv.

Parameters
string$haystackthe string to search in
string$needleone or more charachters to search for
int$offsetoffset from begining of string
Return values
intthe numeric position of the first occurrence of needle in haystack.

◆ strrchr()

static core_text::strrchr (   $haystack,
  $needle,
  $part = false 
)
static

Finds the last occurrence of a character in a string within another.

UTF-8 ONLY safe mb_strrchr().

Parameters
string$haystackThe string from which to get the last occurrence of needle.
string$needleThe string to find in haystack.
boolean$partIf true, returns the portion before needle, else return the portion after (including needle).
Return values
string|falseFalse when not found.
Since
Moodle 2.4.6, 2.5.2, 2.6

◆ strrev()

static core_text::strrev (   $str)
static

Reverse UTF-8 multibytes character sets (used for RTL languages) (We only do this because there is no mb_strrev or iconv_strrev)

Parameters
string$strthe multibyte string to reverse
Return values
stringthe reversed multi byte string

◆ strrpos()

static core_text::strrpos (   $haystack,
  $needle 
)
static

Find the position of the last occurrence of a substring in a string UTF-8 ONLY safe strrpos(), uses mbstring, falls back to iconv.

Parameters
string$haystackthe string to search in
string$needleone or more charachters to search for
Return values
intthe numeric position of the last occurrence of needle in haystack

◆ strtolower()

static core_text::strtolower (   $text,
  $charset = 'utf-8' 
)
static

Multibyte safe strtolower() function, uses mbstring, falls back to typo3.

Parameters
string$textinput string
string$charsetencoding of the text (may not work for all encodings)
Return values
stringlower case text

◆ strtotitle()

static core_text::strtotitle (   $text)
static

Makes first letter of each word capital - words must be separated by spaces.

Use with care, this function does not work properly in many locales!!!

Parameters
string$textinput string
Return values
string

◆ strtoupper()

static core_text::strtoupper (   $text,
  $charset = 'utf-8' 
)
static

Multibyte safe strtoupper() function, uses mbstring, falls back to typo3.

Parameters
string$textinput string
string$charsetencoding of the text (may not work for all encodings)
Return values
stringupper case text

◆ substr()

static core_text::substr (   $text,
  $start,
  $len = null,
  $charset = 'utf-8' 
)
static

Multibyte safe substr() function, uses mbstring or iconv for UTF-8, falls back to typo3.

Parameters
string$textstring to truncate
int$startnegative value means from end
int$lenmaximum length of characters beginning from start
string$charsetencoding of the text
Return values
stringportion of string specified by the $start and $len

◆ trim_utf8_bom()

static core_text::trim_utf8_bom (   $str)
static

Removes the BOM from unicode string

Parameters
string$strinput string
Return values
string

◆ typo3()

static core_text::typo3 (   $reset = false)
staticprotected

Return t3lib helper class, which is used for conversion between charsets.

Parameters
bool$reset
Return values
t3lib_cs

◆ utf8_to_entities()

static core_text::utf8_to_entities (   $str,
  $dec = false,
  $nonnum = false 
)
static

Converts all Unicode chars > 127 to numeric entities &#nnnn; or &#xnnn;.

Parameters
string$strinput string
boolean$decoutput decadic only number entities
boolean$nonnumremove all non-numeric entities
Return values
stringconverted string

◆ utf8ord()

static core_text::utf8ord (   $utf8char)
static

Returns the code of the given UTF-8 character.

Parameters
string$utf8charone UTF-8 character
Return values
intthe code of the given character

The documentation for this class was generated from the following file: