Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $priceList = $_GET['priceList'];
- $priceList = str_replace("\r\n", "", $priceList);
- $pattern = "/\s*<tr>\s*<td>\s*([^<]+)\s*<\/td>\s*<td>\s*([^<]+)\s*<\/td>\s*<td>\s*([0-9.]+)\s*<\/td>\s*<td>\s*(\w+)\s*<\/td>\s*<\/tr>\s*/";
- preg_match_all($pattern, $priceList, $matches, PREG_SET_ORDER);
- $productList = array();
- foreach ($matches as $match) {
- $match[1] = html_entity_decode($match[1]);
- $match[2] = trim(html_entity_decode($match[2]));
- $match[3] = html_entity_decode($match[3]);
- $match[4] = html_entity_decode($match[4]);
- $product = array('product' => $match[1], 'price' => $match[3], 'currency' => $match[4]);
- if (!array_key_exists($match[2], $productList)) {
- $productList[$match[2]] = array();
- }
- array_push($productList[$match[2]], $product);
- }
- ksort($productList);
- foreach ($productList as &$category) {
- sort($category);
- }
- echo json_encode($productList);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement