3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extractColumnData($html,$key){ if(!preg_match("~\.put\('\d+',\s+(.+?)\);~",$html,$out)){ return "alert yourself of the preg_match failure"; } if(($array=@json_decode($out[1],true))===null && json_last_error()!==JSON_ERROR_NONE){ return "alert yourself of the json decode failure"; } return array_column(current(array_column(current($array),'options')),$key,'name'); // this assumes the static structure of your json/array data } $html=<<<HTML <script> HZ.productVariation.Manager.setSpaceId('33503761'); HZ.data.Variations.put('33503761', {"availVar": [{"id": "c", "label": "Color", "options": [{"name": "Chrome", "avail": 1, "stock": 1, "price": "$174.51", "quantity": "52", "imageId": "3eb1230d05775d3c"}, {"name": "SuperSteel", "avail": 1, "stock": 0, "price": "$341.40", "quantity": "0", "imageId": "d0a126f505775d3e"}]}], "curVar": {"c": "SuperSteel"}, "exactMatch": true}); HZ.productVariation.Manager.setSelector(HZ.productVariation.ListSelector); HZ.productVariation.Manager.setRenderer(HZ.productVariation.ViewSpaceRenderer); HZ.productVariation.Manager.setHistoryManager(new HZ.productVariation.BrowserHistoryManager("replace")); $('.variationSelectors').append(HZ.productVariation.Manager.drawSelectors('33503761')); HZ.productVariation.Manager.initUI(); </script> HTML; echo "avail => "; var_export(extractColumnData($html,'avail')); echo "\n----\n"; echo "stock => "; var_export(extractColumnData($html,'stock')); echo "\n----\n"; echo "price => "; var_export(extractColumnData($html,'price')); echo "\n----\n"; echo "quantity => "; var_export(extractColumnData($html,'quantity')); echo "\n----\n"; echo "imageId => "; var_export(extractColumnData($html,'imageId'));

preferences:
29.22 ms | 409 KiB | 5 Q