Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

(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($value)   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 $value Value to unescape
return: string

controlCharacterPHP2OOXML($value)   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 $value Value to escape
return: string

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

param: string $value
return: string

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

param: string $value
return: bool

formatNumber($value)   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: mixed $value
return: string

UTF8toBIFF8UnicodeShort($value, $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 $value UTF-8 encoded string
param: mixed[] $arrcRuns Details of rich text runs in $value
return: string

UTF8toBIFF8UnicodeLong($value)   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 $value UTF-8 encoded string
return: string

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

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

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

param: string $value
param: string $enc Encoding
return: int Character count

substring($pValue, $pStart, $pLength = 0)   X-Ref
Get a substring of a UTF-8 encoded string.

param: string $pValue UTF-8 encoded string
param: int $pStart Start offset
param: int $pLength Maximum number of characters in substring
return: string

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

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

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

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

strToTitle($pValue)   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 $pValue UTF-8 encoded string
return: string

mbIsUpper($char)   X-Ref
No description

mbStrSplit($string)   X-Ref
No description

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

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

convertToNumberIfFraction(&$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
return: bool

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($pValue)   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 $pValue 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($pValue)   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 $pValue 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($pValue)   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 $pValue Character for currency code

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

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

testStringAsNumeric($value)   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 $value
return: mixed string or only the leading numeric part of the string