Package DE_EPAGES::Core::API::String
String manipulation functions
Functions
- CheckForNonPrintableChars
- CompareStrings
- ConvertNewlines
- DecodeStructure
- EncodeNonISO1Chars
- EncodeStructure
- GetWordCount
- QuoteTags
- QuoteXML
- UnquoteXML
- ValidateNewStringLength
CheckForNonPrintableChars
Checks if the given string contains non-printable chars like NUL, BEL, ...
If found, the NON_PRINTABLE_CHARS error is thrown.
Syntax |
$String = CheckForNonPrintableChars($String);
|
Example |
CheckForNonPrintableChars($TestString);
|
Input |
- $String (string)
- input string
|
CompareStrings
Compare two given strings and return how much they are similar. Uses
word based levenshtein comparison ratio.
The $Coverage parameter defines how similar two words have to be to be
rated as equal or as different. The Default value is 0.8 (80%).
The returned $Percentage value is a float number between 0 and 1.0 which
tells how similar the both supplied strings are.
Syntax |
$Percentage = CompareStrings($StringA, $StringB)
|
Input |
- $StringA (string)
- first string
- $StringB (string)
- second string
- $Coverage (float)
- Coverage value for similarity check [0..1]. Default: 0.8 (optional)
|
Return |
- $Percentage (float)
- ratio how similar the strings are [0..1]
|
ConvertNewlines
replace white spaces including newlines with a single space.
Syntax |
$OneLineString = ConvertNewlines($StringWithNewlines)
|
Input |
- $Value (string)
- string containing new lines
|
Return |
- $Value (string)
- one-lined string
|
DecodeStructure
Decodes all strings in a nestes array/hash structure with a given
character encoding. The function creates a copy of the structure. The
original structure is not changed.
Syntax |
$Structure = DecodeStructure( $Encoding, $EncodedStructure )
|
Example |
$Structure = DecodeStructure( 'iso-8859-1', $EncodedStructure );
|
Input |
- $Encoding (string)
- character encoding, example: 'iso-8859-1'
- $EncodedStructure (ref)
- the structure with encoded strings
|
Return |
- $Structure (ref)
- a tree structure of arrays and/or hashes
|
EncodeNonISO1Chars
Syntax |
$Output = EncodeNonISO1Chars( $Input );
|
Example |
"&
|
EncodeStructure
Encodes all strings in a nestes array/hash structure with a given
character encoding. The function creates a copy of the structure. The
original structure is not changed.
Syntax |
$EncodedStructure = EncodeStructure( $Encoding, $Structure )
|
Example |
$EncodedStructure = EncodeStructure( 'iso-8859-1', \%Structure );
|
Input |
- $Encoding (string)
- character encoding, example: 'iso-8859-1'
- $Structure (ref)
- a tree structure of arrays and/or hashes
|
Return |
- $EncodedStructure (ref)
- the structure with encoded strings
|
GetWordCount
Returns the number of words found in a given string.
Syntax |
$Count = GetWordCount($String)
|
Input |
- $String (string)
- text string
|
Return |
- $Count (integer)
- number of words
|
QuoteTags
Replaces the special characters <and> by < and > respectively.
Syntax |
$Output = QuoteTags( $Input );
|
Example |
print QuoteTags( "<bigger>&</bigger>" );
|
Input |
- $Input (string)
- input string
|
Return |
- $Output (string)
- output string
|
QuoteXML
Replaces the special characters &"' by their corresponding XML entities.
Syntax |
$Output = QuoteXML( $Input );
|
Example |
print QuoteXML( "<bigger>&</bigger>" );
|
Input |
- $Input (string)
- input string
|
Return |
- $Output (string)
- output string
|
UnquoteXML
Replaces standard XML entities by the corresponding special characters.
Syntax |
$Output = UnquoteXML( $Input );
|
Input |
- $Input (string)
- input string
|
Return |
- $Output (string)
- output string
|
ValidateNewStringLength
Compares two strings and checks whether the new string has a valid value
that can be written to the DB. Value has to be lower then the max length.
If value is the same, even if it's length is larger that max length it is
still valid, because this change shouldn't invalidate existing products
Syntax |
$IsValid = ValidateNewStringLength($OldString, $NewString, $MaxLength);
|
Input |
- $OldString (string)
- String from the database
- $NewString (string)
- String from the form field
- $MaxLength (number)
- Maximal allowed string length
- $Coverage (float)
- Determines how similar strings should be to be seen as equal
|
Return |
- $boolean (0 or 1)
- 1 if $NewString may be written to db, 0 if not
|