Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DDtMM/f10effb3073ec221c45b to your computer and use it in GitHub Desktop.
Save DDtMM/f10effb3073ec221c45b to your computer and use it in GitHub Desktop.
<?php
$colourJavascript='colourVariantsInitialData=[{"ColVarId":"41103890","PreOrderAvailableDate":"","SizeVariants":[{"SizeName":"UK: 8-13 Kids / EU: 25-32 Kids","SizeVarId":"41103890030","ProdSizePrices":{"SellPrice":"£3.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 1-6 / EU:33-39","SizeVarId":"41103890040","ProdSizePrices":{"SellPrice":"£3.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.00","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 6-11 / EU:39-46","SizeVarId":"41103890060","ProdSizePrices":{"SellPrice":"£4.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 11-14 / EU:46-49","SizeVarId":"41103890070","ProdSizePrices":{"SellPrice":"£4.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.00","ShowFrom":false},"State":"Green"}],"ProdImages":{"ImgUrlThumbNail":"http://images.sportsdirect.com/images/products/41103890_pit.jpg","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xxl.jpg","ImgUrl":"http://images.sportsdirect.com/images/products/41103890_l.jpg","HasImgProdSash":true,"ImgProdSashUrl":"/images/sash/productsash_70off.png","ZoomCss":"spinzoom zoomOnly","ImgCtrlsVisible":true,"HasZoom":true,"HasSeparator":false,"HasSpin":false,"ZoomTxt":"Zoom","SpinTxt":"Spin","SpinCss":"spinControl spinControlWide","AColboxZoomHRef":"/DesktopModules/SportsDirect/ProductDetail/Zoom.aspx?colcode=41103890\u0026cv=41103890\u0026zin=1234\u0026st=1","AColboxZoomTitle":"Donnay 10 Pack Trainer Socks - £3.49","AColbox360HRef":null,"AColorbox360Title":null,"AlternateImages":[{"Id":"apiThumb1","ImgId":"piThumb1","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103890_l.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103890_pit.jpg","CssClasses":"piThumb piActiveThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xxl.jpg"},{"Id":"apiThumb2","ImgId":"piThumb2","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103890_l_a1.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103890_piat_a1.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xl_a1.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xxl_a1.jpg"},{"Id":"apiThumb3","ImgId":"piThumb3","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103890_l_a2.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103890_piat_a2.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xl_a2.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xxl_a2.jpg"},{"Id":"apiThumb4","ImgId":"piThumb4","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103890_l_a3.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103890_piat_a3.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xl_a3.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103890_xxl_a3.jpg"}]},"ProdVarPrices":{"SellPrice":"£3.49","RefPrice":"£3.49","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":false,"YouSave":false,"YouSaveText":null,"ShowFrom":true}},{"ColVarId":"41103899","PreOrderAvailableDate":"","SizeVariants":[{"SizeName":"UK: 8-13 Kids / EU: 25-32 Kids","SizeVarId":"41103899030","ProdSizePrices":{"SellPrice":"£3.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 1-6 / EU:33-39","SizeVarId":"41103899040","ProdSizePrices":{"SellPrice":"£3.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.00","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 6-11 / EU:39-46","SizeVarId":"41103899060","ProdSizePrices":{"SellPrice":"£4.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 11-14 / EU:46-49","SizeVarId":"41103899070","ProdSizePrices":{"SellPrice":"£4.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.00","ShowFrom":false},"State":"Green"}],"ProdImages":{"ImgUrlThumbNail":"http://images.sportsdirect.com/images/products/41103899_pit.jpg","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xxl.jpg","ImgUrl":"http://images.sportsdirect.com/images/products/41103899_l.jpg","HasImgProdSash":true,"ImgProdSashUrl":"/images/sash/productsash_70off.png","ZoomCss":"spinzoom zoomOnly","ImgCtrlsVisible":true,"HasZoom":true,"HasSeparator":false,"HasSpin":false,"ZoomTxt":"Zoom","SpinTxt":"Spin","SpinCss":"spinControl spinControlWide","AColboxZoomHRef":"/DesktopModules/SportsDirect/ProductDetail/Zoom.aspx?colcode=41103899\u0026cv=41103899\u0026zin=1234\u0026st=1","AColboxZoomTitle":"Donnay 10 Pack Trainer Socks - £3.49","AColbox360HRef":null,"AColorbox360Title":null,"AlternateImages":[{"Id":"apiThumb1","ImgId":"piThumb1","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103899_l.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103899_pit.jpg","CssClasses":"piThumb piActiveThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xxl.jpg"},{"Id":"apiThumb2","ImgId":"piThumb2","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103899_l_a1.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103899_piat_a1.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xl_a1.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xxl_a1.jpg"},{"Id":"apiThumb3","ImgId":"piThumb3","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103899_l_a2.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103899_piat_a2.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xl_a2.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xxl_a2.jpg"},{"Id":"apiThumb4","ImgId":"piThumb4","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103899_l_a3.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103899_piat_a3.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xl_a3.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103899_xxl_a3.jpg"}]},"ProdVarPrices":{"SellPrice":"£3.49","RefPrice":"£3.49","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":false,"YouSave":false,"YouSaveText":null,"ShowFrom":true}},{"ColVarId":"41103801","PreOrderAvailableDate":"","SizeVariants":[{"SizeName":"UK: 8-13 Kids / EU: 25-32 Kids","SizeVarId":"41103801030","ProdSizePrices":{"SellPrice":"£3.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 1-6 / EU:33-39","SizeVarId":"41103801040","ProdSizePrices":{"SellPrice":"£3.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£13.00","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 6-11 / EU:39-46","SizeVarId":"41103801060","ProdSizePrices":{"SellPrice":"£4.49","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.50","ShowFrom":false},"State":"Green"},{"SizeName":"UK: 11-14 / EU:46-49","SizeVarId":"41103801070","ProdSizePrices":{"SellPrice":"£4.99","RefPrice":"£16.99","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":true,"YouSave":true,"YouSaveText":"£12.00","ShowFrom":false},"State":"Green"}],"ProdImages":{"ImgUrlThumbNail":"http://images.sportsdirect.com/images/products/41103801_pit.jpg","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xxl.jpg","ImgUrl":"http://images.sportsdirect.com/images/products/41103801_l.jpg","HasImgProdSash":true,"ImgProdSashUrl":"/images/sash/productsash_70off.png","ZoomCss":"spinzoom zoomOnly","ImgCtrlsVisible":true,"HasZoom":true,"HasSeparator":false,"HasSpin":false,"ZoomTxt":"Zoom","SpinTxt":"Spin","SpinCss":"spinControl spinControlWide","AColboxZoomHRef":"/DesktopModules/SportsDirect/ProductDetail/Zoom.aspx?colcode=41103801\u0026cv=41103801\u0026zin=123\u0026st=1","AColboxZoomTitle":"Donnay 10 Pack Trainer Socks - £3.49","AColbox360HRef":null,"AColorbox360Title":null,"AlternateImages":[{"Id":"apiThumb1","ImgId":"piThumb1","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103801_l.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103801_pit.jpg","CssClasses":"piThumb piActiveThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xl.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xxl.jpg"},{"Id":"apiThumb2","ImgId":"piThumb2","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103801_l_a1.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103801_piat_a1.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xl_a1.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xxl_a1.jpg"},{"Id":"apiThumb3","ImgId":"piThumb3","ImgUrlLarge":"http://images.sportsdirect.com/images/products/41103801_l_a2.jpg","ImgUrlThumb":"http://images.sportsdirect.com/images/products/41103801_piat_a2.jpg","CssClasses":"piThumb","ImgUrlXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xl_a2.jpg","ImgUrlXXLarge":"http://images.sportsdirect.com/images/imgzoom/41/41103801_xxl_a2.jpg"}]},"ProdVarPrices":{"SellPrice":"£3.49","RefPrice":"£3.49","SellNoPence":false,"RefNoPence":false,"ShowRefPrice":false,"YouSave":false,"YouSaveText":null,"ShowFrom":true}}]';
$colourJavascript = preg_replace('/^[^=]+=/', '', $colourJavascript);
$data = json_decode($colourJavascript);
print_r($data[0]->SizeVariants[0]->ProdSizePrices->SellPrice . "<br />");
print_r($data[0]->SizeVariants[1]->ProdSizePrices->SellPrice . "<br />");
print_r($data[0]->SizeVariants[2]->ProdSizePrices->SellPrice . "<br />");
// parse a currency value
$formatter = new NumberFormatter("en-GB", \NumberFormatter::CURRENCY);
$priceRaw = $data[0]->SizeVariants[0]->ProdSizePrices->SellPrice;
print_r($formatter->parse($priceRaw));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment