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: 701 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: StringHelper  - X-Ref

buildControlCharacters()   X-Ref
Build control characters array.


buildSYLKCharacters()   X-Ref
Build SYLK characters array.


getIsIconvEnabled()   X-Ref
Get whether iconv extension is available.

return: bool

buildCharacterSets()   X-Ref
No description

controlCharacterOOXML2PHP($textValue)   X-Ref
Convert from OpenXML escaped control character to PHP control character.

Excel 2007 team:
----------------
That's correct, control characters are stored directly in the shared-strings table.
We do encode characters that cannot be represented in XML using the following escape sequence:
_xHHHH_ where H represents a hexadecimal character in the character's value...
So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
element or in the shared string <t> element.

param: string $textValue Value to unescape
return: string

controlCharacterPHP2OOXML($textValue)   X-Ref
Convert from PHP control character to OpenXML escaped control character.

Excel 2007 team:
----------------
That's correct, control characters are stored directly in the shared-strings table.
We do encode characters that cannot be represented in XML using the following escape sequence:
_xHHHH_ where H represents a hexadecimal character in the character's value...
So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
element or in the shared string <t> element.

param: string $textValue Value to escape
return: string

sanitizeUTF8(string $textValue)   X-Ref
Try to sanitize UTF8, replacing invalid sequences with Unicode substitution characters.


returnString($value)   X-Ref
Strictly to satisfy Scrutinizer.

param: mixed $value

isUTF8(string $textValue)   X-Ref
Check if a string contains UTF8 data.


formatNumber($numericValue)   X-Ref
Formats a numeric value as a string for output in various output writers forcing
point as decimal separator in case locale is other than English.

param: float|int|string $numericValue

UTF8toBIFF8UnicodeShort(string $textValue, array $arrcRuns = [])   X-Ref
Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length)
Writes the string using uncompressed notation, no rich text, no Asian phonetics
If mbstring extension is not available, ASCII is assumed, and compressed notation is used
although this will give wrong results for non-ASCII strings
see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3.

param: string $textValue UTF-8 encoded string
param: mixed[] $arrcRuns Details of rich text runs in $value

UTF8toBIFF8UnicodeLong(string $textValue)   X-Ref
Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length)
Writes the string using uncompressed notation, no rich text, no Asian phonetics
If mbstring extension is not available, ASCII is assumed, and compressed notation is used
although this will give wrong results for non-ASCII strings
see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3.

param: string $textValue UTF-8 encoded string

convertEncoding(string $textValue, string $to, string $from)   X-Ref
Convert string from one encoding to another.

param: string $to Encoding to convert to, e.g. 'UTF-8'
param: string $from Encoding to convert from, e.g. 'UTF-16LE'

countCharacters(string $textValue, string $encoding = 'UTF-8')   X-Ref
Get character count.

param: string $encoding Encoding
return: int Character count

substring(string $textValue, int $offset, ?int $length = 0)   X-Ref
Get a substring of a UTF-8 encoded string.

param: string $textValue UTF-8 encoded string
param: int $offset Start offset
param: ?int $length Maximum number of characters in substring

strToUpper(string $textValue)   X-Ref
Convert a UTF-8 encoded string to upper case.

param: string $textValue UTF-8 encoded string

strToLower(string $textValue)   X-Ref
Convert a UTF-8 encoded string to lower case.

param: string $textValue UTF-8 encoded string

strToTitle(string $textValue)   X-Ref
Convert a UTF-8 encoded string to title/proper case
(uppercase every first character in each word, lower case all other characters).

param: string $textValue UTF-8 encoded string

mbIsUpper(string $character)   X-Ref
No description

mbStrSplit(string $string)   X-Ref
Splits a UTF-8 string into an array of individual characters.


strCaseReverse(string $textValue)   X-Ref
Reverse the case of a string, so that all uppercase characters become lowercase
and all lowercase characters become uppercase.

param: string $textValue UTF-8 encoded string

convertToNumberIfFraction(string &$operand)   X-Ref
Identify whether a string contains a fractional numeric value,
and convert it to a numeric if it is.

param: string $operand string value to test

getDecimalSeparator()   X-Ref
Get the decimal separator. If it has not yet been set explicitly, try to obtain number
formatting information from locale.


setDecimalSeparator(string $separator)   X-Ref
Set the decimal separator. Only used by NumberFormat::toFormattedString()
to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

param: string $separator Character for decimal separator

getThousandsSeparator()   X-Ref
Get the thousands separator. If it has not yet been set explicitly, try to obtain number
formatting information from locale.


setThousandsSeparator(string $separator)   X-Ref
Set the thousands separator. Only used by NumberFormat::toFormattedString()
to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

param: string $separator Character for thousands separator

getCurrencyCode()   X-Ref
Get the currency code. If it has not yet been set explicitly, try to obtain the
symbol information from locale.


setCurrencyCode(string $currencyCode)   X-Ref
Set the currency code. Only used by NumberFormat::toFormattedString()
to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.

param: string $currencyCode Character for currency code

SYLKtoUTF8(string $textValue)   X-Ref
Convert SYLK encoded string to UTF-8.

param: string $textValue SYLK encoded string
return: string UTF-8 encoded string

testStringAsNumeric($textValue)   X-Ref
Retrieve any leading numeric part of a string, or return the full string if no leading numeric
(handles basic integer or float, but not exponent or non decimal).

param: string $textValue
return: mixed string or only the leading numeric part of the string