Search code examples
phpparsingtlv

Convert TLV to PHP array


I have a Type Length Value string:

a:4:{s:5:"value";s:4:"0.00";s:4:"type";N;s:12:"discounttype";s:10:"Percentage";s:13:"configoptions";N;}

Is it possible to convert it to PHP array or JSON string?


Solution

  • That kind of string could be done with unserialize() function. Also there is an article about that solving your needs here.

    After it has been unserialized, it is an array. You can then convert using json_encode() function.

    If you need extra help, write a comment