class StringHelper (View source)

Constants

STRING_REGEXP_FRACTION

Methods

static bool
getIsIconvEnabled()

Get whether iconv extension is available.

static string
controlCharacterOOXML2PHP(string $value)

Convert from OpenXML escaped control character to PHP control character.

static string
controlCharacterPHP2OOXML(string $value)

Convert from PHP control character to OpenXML escaped control character.

static string
sanitizeUTF8(string $value)

Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.

static bool
isUTF8(string $value)

Check if a string contains UTF8 data.

static string
formatNumber(mixed $value)

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 string
UTF8toBIFF8UnicodeShort(string $value, mixed[] $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. 2.5.3.

static string
UTF8toBIFF8UnicodeLong(string $value)

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.

static string
convertEncoding(string $value, string $to, string $from)

Convert string from one encoding to another.

static int
countCharacters(string $value, string $enc = 'UTF-8')

Get character count.

static string
substring(string $pValue, int $pStart, int $pLength = 0)

Get a substring of a UTF-8 encoded string.

static string
strToUpper(string $pValue)

Convert a UTF-8 encoded string to upper case.

static string
strToLower(string $pValue)

Convert a UTF-8 encoded string to lower case.

static string
strToTitle(string $pValue)

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

static 
mbIsUpper($char)

No description

static 
mbStrSplit($string)

No description

static string
strCaseReverse(string $pValue)

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

static bool
convertToNumberIfFraction(string $operand)

Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is.

static string
getDecimalSeparator()

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

static 
setDecimalSeparator(string $pValue)

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

static string
getThousandsSeparator()

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

static 
setThousandsSeparator(string $pValue)

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

static string
getCurrencyCode()

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

static 
setCurrencyCode(string $pValue)

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

static string
SYLKtoUTF8(string $pValue)

Convert SYLK encoded string to UTF-8.

static mixed
testStringAsNumeric(string $value)

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

Details

static bool getIsIconvEnabled()

Get whether iconv extension is available.

Return Value

bool

static string controlCharacterOOXML2PHP(string $value)

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

Parameters

string $value Value to unescape

Return Value

string

static string controlCharacterPHP2OOXML(string $value)

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

Parameters

string $value Value to escape

Return Value

string

static string sanitizeUTF8(string $value)

Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.

Parameters

string $value

Return Value

string

static bool isUTF8(string $value)

Check if a string contains UTF8 data.

Parameters

string $value

Return Value

bool

static string formatNumber(mixed $value)

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.

Parameters

mixed $value

Return Value

string

static string UTF8toBIFF8UnicodeShort(string $value, mixed[] $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. 2.5.3.

Parameters

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

Return Value

string

static string UTF8toBIFF8UnicodeLong(string $value)

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 $value UTF-8 encoded string

Return Value

string

static string convertEncoding(string $value, string $to, string $from)

Convert string from one encoding to another.

Parameters

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

Return Value

string

static int countCharacters(string $value, string $enc = 'UTF-8')

Get character count.

Parameters

string $value
string $enc Encoding

Return Value

int Character count

static string substring(string $pValue, int $pStart, int $pLength = 0)

Get a substring of a UTF-8 encoded string.

Parameters

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

Return Value

string

static string strToUpper(string $pValue)

Convert a UTF-8 encoded string to upper case.

Parameters

string $pValue UTF-8 encoded string

Return Value

string

static string strToLower(string $pValue)

Convert a UTF-8 encoded string to lower case.

Parameters

string $pValue UTF-8 encoded string

Return Value

string

static string strToTitle(string $pValue)

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

Parameters

string $pValue UTF-8 encoded string

Return Value

string

static mbIsUpper($char)

Parameters

$char

static mbStrSplit($string)

Parameters

$string

static string strCaseReverse(string $pValue)

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

Parameters

string $pValue UTF-8 encoded string

Return Value

string

static bool convertToNumberIfFraction(string $operand)

Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is.

Parameters

string $operand &$operand string value to test

Return Value

bool

static string getDecimalSeparator()

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

Return Value

string

static setDecimalSeparator(string $pValue)

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

Parameters

string $pValue Character for decimal separator

static string getThousandsSeparator()

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

Return Value

string

static setThousandsSeparator(string $pValue)

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

Parameters

string $pValue Character for thousands separator

static string getCurrencyCode()

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

Return Value

string

static setCurrencyCode(string $pValue)

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

Parameters

string $pValue Character for currency code

static string SYLKtoUTF8(string $pValue)

Convert SYLK encoded string to UTF-8.

Parameters

string $pValue

Return Value

string UTF-8 encoded string

static mixed testStringAsNumeric(string $value)

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

Parameters

string $value

Return Value

mixed string or only the leading numeric part of the string