Documentation

StringHelper
in package

Table of Contents

Properties

$controlCharacters  : array<string|int, string>
Control characters array.
$currencyCode  : string|null
Currency code.
$decimalSeparator  : string|null
Decimal separator.
$iconvOptions  : string
iconv options.
$isIconvEnabled  : bool|null
Is iconv extension avalable?
$SYLKCharacters  : array<string|int, mixed>
SYLK Characters array.
$thousandsSeparator  : string|null
Thousands separator.

Methods

controlCharacterOOXML2PHP()  : string
Convert from OpenXML escaped control character to PHP control character.
controlCharacterPHP2OOXML()  : string
Convert from PHP control character to OpenXML escaped control character.
convertEncoding()  : string
Convert string from one encoding to another.
countCharacters()  : int
Get character count.
countCharactersDbcs()  : int
Get character count using mb_strwidth rather than mb_strlen.
formatNumber()  : string
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.
getCurrencyCode()  : string
Get the currency code. If it has not yet been set explicitly, try to obtain the symbol information from locale.
getDecimalSeparator()  : string
Get the decimal separator. If it has not yet been set explicitly, try to obtain number formatting information from locale.
getIsIconvEnabled()  : bool
Get whether iconv extension is available.
getThousandsSeparator()  : string
Get the thousands separator. If it has not yet been set explicitly, try to obtain number formatting information from locale.
isUTF8()  : bool
Check if a string contains UTF8 data.
mbIsUpper()  : bool
mbStrSplit()  : array<string|int, mixed>
Splits a UTF-8 string into an array of individual characters.
sanitizeUTF8()  : string
Try to sanitize UTF8, replacing invalid sequences with Unicode substitution characters.
setCurrencyCode()  : void
Set the currency code. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.
setDecimalSeparator()  : void
Set the decimal separator. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.
setThousandsSeparator()  : void
Set the thousands separator. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf.
strCaseReverse()  : string
Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase.
strToLower()  : string
Convert a UTF-8 encoded string to lower case.
strToTitle()  : string
Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word, lower case all other characters).
strToUpper()  : string
Convert a UTF-8 encoded string to upper case.
substring()  : string
Get a substring of a UTF-8 encoded string.
SYLKtoUTF8()  : string
Convert SYLK encoded string to UTF-8.
testStringAsNumeric()  : float|string
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).
UTF8toBIFF8UnicodeLong()  : string
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.
UTF8toBIFF8UnicodeShort()  : string
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.
buildCharacterSets()  : void
buildControlCharacters()  : void
Build control characters array.
buildSYLKCharacters()  : void
Build SYLK characters array.

Properties

$controlCharacters

Control characters array.

private static array<string|int, string> $controlCharacters = []

$currencyCode

Currency code.

private static string|null $currencyCode

$decimalSeparator

Decimal separator.

private static string|null $decimalSeparator

$iconvOptions

iconv options.

private static string $iconvOptions = '//IGNORE//TRANSLIT'

$isIconvEnabled

Is iconv extension avalable?

private static bool|null $isIconvEnabled

$SYLKCharacters

SYLK Characters array.

private static array<string|int, mixed> $SYLKCharacters = []

$thousandsSeparator

Thousands separator.

private static string|null $thousandsSeparator

Methods

controlCharacterOOXML2PHP()

Convert from OpenXML escaped control character to PHP control character.

public static controlCharacterOOXML2PHP(string $textValue) : string

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 () element or in the shared string element.

Parameters
$textValue : string

Value to unescape

Return values
string

controlCharacterPHP2OOXML()

Convert from PHP control character to OpenXML escaped control character.

public static controlCharacterPHP2OOXML(string $textValue) : string

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 () element or in the shared string element.

Parameters
$textValue : string

Value to escape

Return values
string

convertEncoding()

Convert string from one encoding to another.

public static convertEncoding(string $textValue, string $to, string $from) : string
Parameters
$textValue : string
$to : string

Encoding to convert to, e.g. 'UTF-8'

$from : string

Encoding to convert from, e.g. 'UTF-16LE'

Return values
string

countCharacters()

Get character count.

public static countCharacters(string $textValue[, string $encoding = 'UTF-8' ]) : int
Parameters
$textValue : string
$encoding : string = 'UTF-8'

Encoding

Return values
int

Character count

countCharactersDbcs()

Get character count using mb_strwidth rather than mb_strlen.

public static countCharactersDbcs(string $textValue[, string $encoding = 'UTF-8' ]) : int
Parameters
$textValue : string
$encoding : string = 'UTF-8'

Encoding

Return values
int

Character count

formatNumber()

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.

public static formatNumber(float|int|string|null $numericValue) : string
Parameters
$numericValue : float|int|string|null
Return values
string

getCurrencyCode()

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

public static getCurrencyCode() : string
Return values
string

getDecimalSeparator()

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

public static getDecimalSeparator() : string
Return values
string

getIsIconvEnabled()

Get whether iconv extension is available.

public static getIsIconvEnabled() : bool
Return values
bool

getThousandsSeparator()

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

public static getThousandsSeparator() : string
Return values
string

isUTF8()

Check if a string contains UTF8 data.

public static isUTF8(string $textValue) : bool
Parameters
$textValue : string
Return values
bool

mbIsUpper()

public static mbIsUpper(string $character) : bool
Parameters
$character : string
Return values
bool

mbStrSplit()

Splits a UTF-8 string into an array of individual characters.

public static mbStrSplit(string $string) : array<string|int, mixed>
Parameters
$string : string
Return values
array<string|int, mixed>

sanitizeUTF8()

Try to sanitize UTF8, replacing invalid sequences with Unicode substitution characters.

public static sanitizeUTF8(string $textValue) : string
Parameters
$textValue : string
Return values
string

setCurrencyCode()

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

public static setCurrencyCode(string|null $currencyCode) : void
Parameters
$currencyCode : string|null

Character for currency code

setDecimalSeparator()

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

public static setDecimalSeparator(string|null $separator) : void
Parameters
$separator : string|null

Character for decimal separator

setThousandsSeparator()

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

public static setThousandsSeparator(string|null $separator) : void
Parameters
$separator : string|null

Character for thousands separator

strCaseReverse()

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

public static strCaseReverse(string $textValue) : string
Parameters
$textValue : string

UTF-8 encoded string

Return values
string

strToLower()

Convert a UTF-8 encoded string to lower case.

public static strToLower(string $textValue) : string
Parameters
$textValue : string

UTF-8 encoded string

Return values
string

strToTitle()

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

public static strToTitle(string $textValue) : string
Parameters
$textValue : string

UTF-8 encoded string

Return values
string

strToUpper()

Convert a UTF-8 encoded string to upper case.

public static strToUpper(string $textValue) : string
Parameters
$textValue : string

UTF-8 encoded string

Return values
string

substring()

Get a substring of a UTF-8 encoded string.

public static substring(string $textValue, int $offset[, int|null $length = 0 ]) : string
Parameters
$textValue : string

UTF-8 encoded string

$offset : int

Start offset

$length : int|null = 0

Maximum number of characters in substring

Return values
string

SYLKtoUTF8()

Convert SYLK encoded string to UTF-8.

public static SYLKtoUTF8(string $textValue) : string
Parameters
$textValue : string

SYLK encoded string

Return values
string

UTF-8 encoded string

testStringAsNumeric()

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

public static testStringAsNumeric(string $textValue) : float|string
Parameters
$textValue : string
Return values
float|string

string or only the leading numeric part of the string

UTF8toBIFF8UnicodeLong()

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.

public static UTF8toBIFF8UnicodeLong(string $textValue) : string
Parameters
$textValue : string

UTF-8 encoded string

Return values
string

UTF8toBIFF8UnicodeShort()

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.

public static UTF8toBIFF8UnicodeShort(string $textValue[, array<int, array{strlen: int, fontidx: int}> $arrcRuns = [] ]) : string
Parameters
$textValue : string

UTF-8 encoded string

$arrcRuns : array<int, array{strlen: int, fontidx: int}> = []

Details of rich text runs in $value

Return values
string

buildCharacterSets()

private static buildCharacterSets() : void

buildControlCharacters()

Build control characters array.

private static buildControlCharacters() : void

buildSYLKCharacters()

Build SYLK characters array.

private static buildSYLKCharacters() : void

        
On this page

Search results