Parsing Valve Data Format Files in PHP

I am completely stuck on how to start parsing these files in PHP. These are kind of arrays with a variable number of sub-arrays. https://developer.valvesoftware.com/wiki/KeyValues

Sample file.

"itembuilds" { "author" "Valve" "hero" "npc_dota_hero_axe" "Title" "Recommended items for Axe" "Items" { "#DOTA_Item_Build_Starting_Items" { "item" "item_stout_shield" "item" "item_flask" "item" "item_tango" "item" "item_courier" } "#DOTA_Item_Build_Early_Game" { "item" "item_boots" "item" "item_ring_of_health" "item" "item_tango" "item" "item_tango" } "#DOTA_Item_Build_Core_Items" { "item" "item_blink" "item" "item_vanguard" } "#DOTA_Item_Build_Luxury" { "item" "item_heart" "item" "item_blade_mail" } } } 

Another example file.

 "dota_shops" { "consumables" { "item" "item_clarity" "item" "item_tango" "item" "item_flask" "item" "item_smoke_of_deceit" "item" "item_tpscroll" "item" "item_dust" "item" "item_courier" "item" "item_flying_courier" "item" "item_ward_observer" "item" "item_ward_sentry" "item" "item_bottle" } "something" { "Key" "value" "Key2" "value" } } 
+1
source share
2 answers

Late answer, but just saw it. The data in question is in (Valve Data Format) [https://developer.valvesoftware.com/wiki/KeyValues], also called KeyValues ​​format and is very similar to JSON.

About a year ago, I wrote this script that can convert VDF data to valid JSON. You can use it once and save the generated JSON or call it anytime you need JSON from VDF.

https://gist.github.com/AlienHoboken/5571903

0
source

There I found online. http://rossengeorgiev.imtqy.com/vdf-parser/

The repo has an implementation of js and python, it should not be too difficult to port them to PHP.

0
source

All Articles