Documentation

StringHelper

Table of Contents

STRING_REGEXP_FRACTION '(-?)(\\d+)\\s+(\\d+\\/\\d+)'
$controlCharacters Control characters array. string[]
$SYLKCharacters SYLK Characters array. array
$decimalSeparator Decimal separator. string
$thousandsSeparator Thousands separator. string
$currencyCode Currency code. string
$isIconvEnabled Is iconv extension avalable? bool
$iconvOptions iconv options. string
buildControlCharacters() Build control characters array. void
buildSYLKCharacters() Build SYLK characters array. void
getIsIconvEnabled() Get whether iconv extension is available. bool
buildCharacterSets() void
controlCharacterOOXML2PHP() Convert from OpenXML escaped control character to PHP control character. string
controlCharacterPHP2OOXML() Convert from PHP control character to OpenXML escaped control character. string
sanitizeUTF8() Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters. string
isUTF8() Check if a string contains UTF8 data. bool
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. 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. 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. string
convertEncoding() Convert string from one encoding to another. string
countCharacters() Get character count. int
substring() Get a substring of a UTF-8 encoded string. string
strToUpper() Convert a UTF-8 encoded string to upper case. string
strToLower() Convert a UTF-8 encoded string to lower case. string
strToTitle() Convert a UTF-8 encoded string to title/proper case (uppercase every first character in each word, lower case all other characters). string
mbIsUpper() mixed
mbStrSplit() mixed
strCaseReverse() Reverse the case of a string, so that all uppercase characters become lowercase and all lowercase characters become uppercase. string
convertToNumberIfFraction() Identify whether a string contains a fractional numeric value, and convert it to a numeric if it is. bool
getDecimalSeparator() Get the decimal separator. If it has not yet been set explicitly, try to obtain number formatting information from locale. string
setDecimalSeparator() Set the decimal separator. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. void
getThousandsSeparator() Get the thousands separator. If it has not yet been set explicitly, try to obtain number formatting information from locale. string
setThousandsSeparator() Set the thousands separator. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. void
getCurrencyCode() Get the currency code. If it has not yet been set explicitly, try to obtain the symbol information from locale. string
setCurrencyCode() Set the currency code. Only used by NumberFormat::toFormattedString() to format output by \PhpOffice\PhpSpreadsheet\Writer\Html and \PhpOffice\PhpSpreadsheet\Writer\Pdf. void
SYLKtoUTF8() Convert SYLK encoded string to UTF-8. 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). mixed

Constants

STRING_REGEXP_FRACTION

mixed $STRING_REGEXP_FRACTION = '(-?)(\\d+)\\s+(\\d+\\/\\d+)'

Properties

$controlCharacters

Control characters array.

private static string[] $controlCharacters = []

$SYLKCharacters

SYLK Characters array.

private static array $SYLKCharacters = []

$decimalSeparator

Decimal separator.

private static string $decimalSeparator

$thousandsSeparator

Thousands separator.

private static string $thousandsSeparator

$currencyCode

Currency code.

private static string $currencyCode

$isIconvEnabled

Is iconv extension avalable?

private static bool $isIconvEnabled

$iconvOptions

iconv options.

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

Methods

buildControlCharacters()

Build control characters array.

private static buildControlCharacters( ) : void

buildSYLKCharacters()

Build SYLK characters array.

private static buildSYLKCharacters( ) : void

getIsIconvEnabled()

Get whether iconv extension is available.

public static getIsIconvEnabled( ) : bool
Return values
bool

buildCharacterSets()

private static buildCharacterSets( ) : void

controlCharacterOOXML2PHP()

Convert from OpenXML escaped control character to PHP control character.

public static controlCharacterOOXML2PHP( $value : string ) : 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
$value : string

Value to unescape

Return values
string

controlCharacterPHP2OOXML()

Convert from PHP control character to OpenXML escaped control character.

public static controlCharacterPHP2OOXML( $value : string ) : 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
$value : string

Value to escape

Return values
string

sanitizeUTF8()

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

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

isUTF8()

Check if a string contains UTF8 data.

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

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( $value : mixed ) : string
Parameters
$value : mixed
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( $value : string [, $arrcRuns : array = [] ] ) : string
Parameters
$value : string

UTF-8 encoded string

$arrcRuns : array = []

Details of rich text runs in $value

Return values
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( $value : string ) : string
Parameters
$value : string

UTF-8 encoded string

Return values
string

convertEncoding()

Convert string from one encoding to another.

public static convertEncoding( $value : string , $to : string , $from : string ) : string
Parameters
$value : 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( $value : string [, $enc : string = 'UTF-8' ] ) : int
Parameters
$value : string
$enc : string = 'UTF-8'

Encoding

Return values
int

Character count

substring()

Get a substring of a UTF-8 encoded string.

public static substring( $pValue : string , $pStart : int , $pLength : int ) : string
Parameters
$pValue : string

UTF-8 encoded string

$pStart : int

Start offset

$pLength : int

Maximum number of characters in substring

Return values
string

strToUpper()

Convert a UTF-8 encoded string to upper case.

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

UTF-8 encoded string

Return values
string

strToLower()

Convert a UTF-8 encoded string to lower case.

public static strToLower( $pValue : string ) : string
Parameters
$pValue : 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( $pValue : string ) : string
Parameters
$pValue : string

UTF-8 encoded string

Return values
string

mbIsUpper()

public static mbIsUpper( $char : mixed ) : mixed
Parameters
$char : mixed
Return values
mixed

mbStrSplit()

public static mbStrSplit( $string : mixed ) : mixed
Parameters
$string : mixed
Return values
mixed

strCaseReverse()

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

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

UTF-8 encoded string

Return values
string

convertToNumberIfFraction()

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

public static convertToNumberIfFraction( &$operand : mixed ) : bool
Parameters
$operand : mixed
Return values
bool

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

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( $pValue : string ) : void
Parameters
$pValue : string

Character for decimal separator

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

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( $pValue : string ) : void
Parameters
$pValue : string

Character for thousands separator

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

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( $pValue : string ) : void
Parameters
$pValue : string

Character for currency code

SYLKtoUTF8()

Convert SYLK encoded string to UTF-8.

public static SYLKtoUTF8( $pValue : string ) : string
Parameters
$pValue : 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( $value : string ) : mixed
Parameters
$value : string
Return values
mixed

string or only the leading numeric part of the string

Search results