Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250620) (7d9030acd6e)
PhpOffice\PhpSpreadsheet\Shared\StringHelper Class Reference

Static Public Member Functions

static controlCharacterOOXML2PHP (string $textValue)
 Convert from OpenXML escaped control character to PHP control character.
 
static controlCharacterPHP2OOXML (string $textValue)
 Convert from PHP control character to OpenXML escaped control character.
 
static convertEncoding (string $textValue, string $to, string $from)
 Convert string from one encoding to another.
 
static countCharacters (string $textValue, string $encoding='UTF-8')
 Get character count.
 
static countCharactersDbcs (string $textValue, string $encoding='UTF-8')
 Get character count using mb_strwidth rather than mb_strlen.
 
static formatNumber (float|int|string|null $numericValue)
 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.
 
static getCurrencyCode (bool $trimAlt=false)
 Get the currency code.
 
static getDecimalSeparator ()
 Get the decimal separator.
 
static getIsIconvEnabled ()
 Get whether iconv extension is available.
 
static getThousandsSeparator ()
 Get the thousands separator.
 
static isUTF8 (string $textValue)
 Check if a string contains UTF8 data.
 
static mbIsUpper (string $character)
 
static mbStrSplit (string $string)
 Splits a UTF-8 string into an array of individual characters.
 
static sanitizeUTF8 (string $textValue)
 Try to sanitize UTF8, replacing invalid sequences with Unicode substitution characters.
 
static setCurrencyCode (?string $currencyCode)
 Set the currency code.
 
static setDecimalSeparator (?string $separator)
 Set the decimal separator.
 
static setThousandsSeparator (?string $separator)
 Set the thousands separator.
 
static strCaseReverse (string $textValue)
 Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase.
 
static strlenAllowNull (?string $string)
 
static strToLower (string $textValue)
 Convert a UTF-8 encoded string to lower case.
 
static strToTitle (string $textValue)
 Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word, lower case all other characters).
 
static strToUpper (string $textValue)
 Convert a UTF-8 encoded string to upper case.
 
static substring (string $textValue, int $offset, ?int $length=0)
 Get a substring of a UTF-8 encoded string.
 
static SYLKtoUTF8 (string $textValue)
 Convert SYLK encoded string to UTF-8.
 
static testStringAsNumeric (string $textValue)
 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).
 
static UTF8toBIFF8UnicodeLong (string $textValue)
 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.
 
static UTF8toBIFF8UnicodeShort (string $textValue, array $arrcRuns=[])
 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.
 

Member Function Documentation

◆ controlCharacterOOXML2PHP()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterOOXML2PHP ( string $textValue)
static

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.

Parameters
string$textValueValue to unescape

◆ controlCharacterPHP2OOXML()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::controlCharacterPHP2OOXML ( string $textValue)
static

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.

Parameters
string$textValueValue to escape

◆ convertEncoding()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::convertEncoding ( string $textValue,
string $to,
string $from )
static

Convert string from one encoding to another.

Parameters
string$toEncoding to convert to, e.g. 'UTF-8'
string$fromEncoding to convert from, e.g. 'UTF-16LE'

◆ countCharacters()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharacters ( string $textValue,
string $encoding = 'UTF-8' )
static

Get character count.

Parameters
string$encodingEncoding
Return values
intCharacter count

◆ countCharactersDbcs()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::countCharactersDbcs ( string $textValue,
string $encoding = 'UTF-8' )
static

Get character count using mb_strwidth rather than mb_strlen.

Parameters
string$encodingEncoding
Return values
intCharacter count

◆ getCurrencyCode()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getCurrencyCode ( bool $trimAlt = false)
static

Get the currency code.

If it has not yet been set explicitly, try to obtain the symbol information from locale.

◆ getDecimalSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getDecimalSeparator ( )
static

Get the decimal separator.

If it has not yet been set explicitly, try to obtain number formatting information from locale.

◆ getThousandsSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::getThousandsSeparator ( )
static

Get the thousands separator.

If it has not yet been set explicitly, try to obtain number formatting information from locale.

◆ setCurrencyCode()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setCurrencyCode ( ?string $currencyCode)
static

Set the currency code.

Only used by NumberFormat::toFormattedString() to format output by PhpOffice\PhpSpreadsheet\Writer\Html and PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
?string$currencyCodeCharacter for currency code

◆ setDecimalSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setDecimalSeparator ( ?string $separator)
static

Set the decimal separator.

Only used by NumberFormat::toFormattedString() to format output by PhpOffice\PhpSpreadsheet\Writer\Html and PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
?string$separatorCharacter for decimal separator

◆ setThousandsSeparator()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::setThousandsSeparator ( ?string $separator)
static

Set the thousands separator.

Only used by NumberFormat::toFormattedString() to format output by PhpOffice\PhpSpreadsheet\Writer\Html and PhpOffice\PhpSpreadsheet\Writer\Pdf.

Parameters
?string$separatorCharacter for thousands separator

◆ strCaseReverse()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strCaseReverse ( string $textValue)
static

Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase.

Parameters
string$textValueUTF-8 encoded string

◆ strToLower()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToLower ( string $textValue)
static

Convert a UTF-8 encoded string to lower case.

Parameters
string$textValueUTF-8 encoded string

◆ strToTitle()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToTitle ( string $textValue)
static

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

Parameters
string$textValueUTF-8 encoded string

◆ strToUpper()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::strToUpper ( string $textValue)
static

Convert a UTF-8 encoded string to upper case.

Parameters
string$textValueUTF-8 encoded string

◆ substring()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::substring ( string $textValue,
int $offset,
?int $length = 0 )
static

Get a substring of a UTF-8 encoded string.

Parameters
string$textValueUTF-8 encoded string
int$offsetStart offset
?int$lengthMaximum number of characters in substring

◆ SYLKtoUTF8()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::SYLKtoUTF8 ( string $textValue)
static

Convert SYLK encoded string to UTF-8.

Parameters
string$textValueSYLK encoded string
Return values
stringUTF-8 encoded string

◆ testStringAsNumeric()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::testStringAsNumeric ( string $textValue)
static

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 values
float|stringstring or only the leading numeric part of the string

◆ UTF8toBIFF8UnicodeLong()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeLong ( string $textValue)
static

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.

Parameters
string$textValueUTF-8 encoded string

◆ UTF8toBIFF8UnicodeShort()

static PhpOffice\PhpSpreadsheet\Shared\StringHelper::UTF8toBIFF8UnicodeShort ( string $textValue,
array $arrcRuns = [] )
static

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.

Parameters
string$textValueUTF-8 encoded string
array<int,array{strlenint, fontidx: int}> $arrcRuns Details of rich text runs in $value

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