Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i unserialize a string?

I have a menu system that uses a drag and drop tree structure to make it easy for a user to modify. When the javascript serializes the string, it does it in the following way:

// Assume each of these items has an ID on with the respective numbers attached
Menu Item 1
  + Menu Item 2
  + Menu Item 3
     + Menu Item 4
Menu Item 5
Menu Item 6
  + Menu Item 7

This will then get serialized as:

1>2>3>>4#5#6>7

The problem with this is that there could be an arbitrary number of sublevels, which makes it difficult to unserialize. I'm using PHP server side to unserialize it but I am at a loss as to what to do.

Any suggestions welcome, even to the method of serialization, I’ll just hack the code.

like image 333
xenon Avatar asked Mar 14 '26 04:03

xenon


2 Answers

You should look into json_encode/json_decode functions in PHP, those make interacting with Javascript really easy.

With your current serialization format you are just creating headaches for yourself.

like image 176
Anti Veeranna Avatar answered Mar 15 '26 19:03

Anti Veeranna


I think you can split this string first by '#', then each split result splits by regex to exactly "number>number" so ">>" will not be there, then "number>>number" and so on.
Hope it helps.
Sorry for my english.

like image 23
Alexey Ogarkov Avatar answered Mar 15 '26 18:03

Alexey Ogarkov