Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

(no description)

File Size: 722 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.

return: string
param: string $textValue Value to unescape

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.

return: string
param: string $textValue Value to escape

sanitizeUTF8($textValue)   X-Ref
Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.

return: string
param: string $textValue

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

return: bool
param: string $textValue

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.

return: string
param: mixed $numericValue

UTF8toBIFF8UnicodeShort($textValue, $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.

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

UTF8toBIFF8UnicodeLong($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.

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

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

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

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

return: int Character count
param: string $textValue
param: string $encoding Encoding

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

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

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

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

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

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

strToTitle($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).

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

mbIsUpper($character)   X-Ref
No description

mbStrSplit($string)   X-Ref
No description

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

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

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

return: bool
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.

return: string

setDecimalSeparator($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.

return: string

setThousandsSeparator($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.

return: string

setCurrencyCode($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($textValue)   X-Ref
Convert SYLK encoded string to UTF-8.

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

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).

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