\qfq KeyValueStringParser

Class KeyValueStringParser

KeyValueStringParser is a parser for strings of the form

key1<delimiterA>value1<delimiterB>key2<delimiterA>value2<delimiterB>

For instance

id=1,name=doe,firstname=john
  • Leading and trailing whitespace will be removed from keys and values.
  • If a value is surrounded by quotes (', "), leading and trailing whitespace will be preserved (leading/trailing, quotes will be removed from value).
  • Comments, lines starting with a '#' or ';', will be skipped.

Summary

Methods
Properties
Constants
unparse()
parse()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
isFirstAndLastCharacterIdentical()
removeSourroundingQuotes()
No private properties found
N/A

Methods

unparse()

unparse(array  $keyValueArray, string  $keyValueDelimiter = ":", string  $listDelimiter = ",") : string

Parameters

array $keyValueArray
string $keyValueDelimiter
string $listDelimiter

Returns

string

parse()

parse(string  $keyValueString, string  $keyValueDelimiter = ":", string  $listDelimiter = ",", string  $valueMode = KVP_VALUE_GIVEN) : array

Parse key/value pairs string and returns them as an assoc array

Hint $keyValueString: "a:1,b:2,c:,d", "," (empty key AND empty value)

Parameters

string $keyValueString

string of key/value pairs. E.g.: 'a=100,b=test'

string $keyValueDelimiter
string $listDelimiter
string $valueMode
  • VALUE_GIVEN: If only a key is given, the value is ''. E.G. 'a,b' >> [ 'a' => '', 'b' => '' ]
    • IF_VALUE_EMPTY_COPY_KEY: If only a key is given, the value is the same as the key. E.G. 'a,b' >> [ 'a' => 'a', 'b' => 'b' ].

Throws

\qfq\UserFormException

Thrown if there is a value but no key.

Returns

array —

associative array indexed by keys

isFirstAndLastCharacterIdentical()

isFirstAndLastCharacterIdentical(  $string) : boolean

Parameters

$string

Returns

boolean

removeSourroundingQuotes()

removeSourroundingQuotes(  $string) : string

Parameters

$string

Returns

string