Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
|
defines string api's for manipulating strings More...
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) | |
static | convert ($text, $fromCS, $toCS='utf-8') |
Converts the text between different encodings. | |
static | encode_mimeheader ($text, $charset='utf-8') |
Generate a correct base64 encoded header to be used in MIME mail messages. | |
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. | |
static | get_encodings () |
Returns encoding options for select boxes, utf-8 and platform encoding first. | |
static | is_charset_supported (string $charset) |
Check whether the charset is supported by mbstring. | |
static | parse_charset ($charset) |
Standardise charset name. | |
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. | |
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. | |
static | str_max_bytes ($string, $bytes) |
Truncates a string to no more than a certain number of bytes in a multi-byte safe manner. | |
static | strlen ($text, $charset='utf-8') |
Multibyte safe strlen() function, uses mbstring or iconv. | |
static | strpos ($haystack, $needle, $offset=0) |
Find the position of the first occurrence of a substring in a string. | |
static | strrchr ($haystack, $needle, $part=false) |
Finds the last occurrence of a character in a string within another. | |
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) | |
static | strrpos ($haystack, $needle) |
Find the position of the last occurrence of a substring in a string UTF-8 ONLY safe strrpos(), uses mbstring. | |
static | strtolower ($text, $charset='utf-8') |
Multibyte safe strtolower() function, uses mbstring. | |
static | strtotitle ($text) |
Makes first letter of each word capital - words must be separated by spaces. | |
static | strtoupper ($text, $charset='utf-8') |
Multibyte safe strtoupper() function, uses mbstring. | |
static | substr ($text, $start, $len=null, $charset='utf-8') |
Multibyte safe substr() function, uses mbstring or iconv. | |
static | trim_utf8_bom ($str) |
Removes the BOM from unicode string | |
static | utf8_to_entities ($str, $dec=false, $nonnum=false) |
Converts all Unicode chars > 127 to numeric entities &#nnnn; or &#xnnn;. | |
static | utf8ord ($utf8char) |
Returns the code of the given UTF-8 character. | |
Public Attributes | |
string const | UTF8_BOM = "\xef\xbb\xbf" |
Byte order mark for UTF-8. | |
Static Protected Member Functions | |
static | get_entities_table () |
Returns HTML entity transliteration table. | |
Static Protected Attributes | |
static string[] | $noncharacters |
Array of strings representing Unicode non-characters. | |
defines string api's for manipulating strings
This class is used to manipulate strings under Moodle 1.6 an later. As utf-8 text become mandatory a pool of safe functions under this encoding become necessary. The name of the methods is exactly the same than their PHP originals.
This class was previously based on Typo3 which has now been removed and uses native functions now.
|
static |
Returns the utf8 string corresponding to the unicode value (from php.net, courtesy - roman.nosp@m.s@vo.nosp@m.id.lv)
int | $num | one unicode value |
string | the UTF-8 char corresponding to the unicode value |
|
static |
Converts the text between different encodings.
It uses iconv extension with //TRANSLIT parameter. If both source and target are utf-8 it tries to fix invalid characters only.
string | $text | |
string | $fromCS | source encoding |
string | $toCS | result encoding |
string|bool | converted string or false on error |
|
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).
string | $text | input string |
string | $charset | encoding of the text |
string | base64 encoded header |
|
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.
string | $str | input string |
boolean | $htmlent | convert also html entities (defaults to true) |
string | encoded UTF-8 string |
|
static |
Returns encoding options for select boxes, utf-8 and platform encoding first.
array | encodings |
|
staticprotected |
Returns HTML entity transliteration table.
array | with (html entity => utf-8) elements |
|
static |
Check whether the charset is supported by mbstring.
string | $charset | Normalised charset |
bool |
|
static |
Standardise charset name.
Please note it does not mean the returned charset is actually supported.
string | $charset | raw charset name |
string | normalised lowercase charset name |
|
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.
string | $value | Input string |
string | Cleaned string value |
|
static |
|
static |
Try to convert upper unicode characters to plain ascii, the returned string may contain unconverted unicode characters.
With the removal of typo3, iconv conversions was found to be the best alternative to Typo3's function. However using the standard iconv call iconv($charset, 'ASCII//TRANSLIT//IGNORE', (string) $text); resulted in invalid strings with special character from Russian/Japanese. To solve this, the transliterator was used but this resulted in empty strings for certain strings in our test. It was decided to use a combo of the 2 to cover all our bases. Refer MDL-53544 for further information.
string | $text | input string |
string | $charset | encoding of the text |
string | converted ascii string |
|
static |
Truncates a string to no more than a certain number of bytes in a multi-byte safe manner.
UTF-8 only!
string | $string | String to truncate |
int | $bytes | Maximum length of bytes in the result |
string | Portion of string specified by $bytes |
|
static |
Multibyte safe strlen() function, uses mbstring or iconv.
string | $text | input string |
string | $charset | encoding of the text |
int | number of characters |
|
static |
Find the position of the first occurrence of a substring in a string.
UTF-8 ONLY safe strpos(), uses mbstring
string | $haystack | the string to search in |
string | $needle | one or more charachters to search for |
int | $offset | offset from begining of string |
int | the numeric position of the first occurrence of needle in haystack. |
|
static |
Finds the last occurrence of a character in a string within another.
UTF-8 ONLY safe mb_strrchr().
string | $haystack | The string from which to get the last occurrence of needle. |
string | $needle | The string to find in haystack. |
boolean | $part | If true, returns the portion before needle, else return the portion after (including needle). |
string|false | False when not found. |
|
static |
Reverse UTF-8 multibytes character sets (used for RTL languages) (We only do this because there is no mb_strrev or iconv_strrev)
string | $str | the multibyte string to reverse |
string | the reversed multi byte string |
|
static |
Find the position of the last occurrence of a substring in a string UTF-8 ONLY safe strrpos(), uses mbstring.
string | $haystack | the string to search in |
string | $needle | one or more charachters to search for |
int | the numeric position of the last occurrence of needle in haystack |
|
static |
Multibyte safe strtolower() function, uses mbstring.
string | $text | input string |
string | $charset | encoding of the text (may not work for all encodings) |
string | lower case 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!!!
string | $text | input string |
string |
|
static |
Multibyte safe strtoupper() function, uses mbstring.
string | $text | input string |
string | $charset | encoding of the text (may not work for all encodings) |
string | upper case text |
|
static |
Multibyte safe substr() function, uses mbstring or iconv.
string | $text | string to truncate |
int | $start | negative value means from end |
int | $len | maximum length of characters beginning from start |
string | $charset | encoding of the text |
string | portion of string specified by the $start and $len |
|
static |
|
static |
Converts all Unicode chars > 127 to numeric entities &#nnnn; or &#xnnn;.
string | $str | input string |
boolean | $dec | output decadic only number entities |
boolean | $nonnum | remove all non-numeric entities |
string | converted string |
|
static |
Returns the code of the given UTF-8 character.
string | $utf8char | one UTF-8 character |
int | the code of the given character |