Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. $priceListTable = html_entity_decode($_GET['priceList']);
  3.  
  4. $pattern = "/[\s\n\r\t]*<tr>[\s\n\r\t]*<td>[\s\n\r]*(.+?)[\s\n\r\t]*<\/td>[\s\n\r\t]*<td>[\s\n\r\t]*(.+?)[\s\n\r\t]*<\/td>[\s\n\r\t]*<td>[\s\n\r\t]*(\d+\.?\d{0,2})[\s\n\r\t]*<\/td>[\s\n\r\t]*<td>[\s\n\r\t]*(.+?)[\s\n\r\t]*<\/td>[\s\n\r\t]*<\/tr>/";
  5. preg_match_all($pattern, $priceListTable, $matches);
  6. $priceList = array();
  7. for ($i=0; $i < sizeof($matches[2]) ; $i++) {
  8.  
  9.  
  10. if(!isset($priceList[$matches[2][$i]])){
  11. $priceList[$matches[2][$i]] = [];
  12.  
  13. }
  14. $temp = array(
  15. "product" => $matches[1][$i],
  16. "price" => $matches[3][$i],
  17. "currency" => $matches[4][$i]
  18. );
  19. $priceList[$matches[2][$i]][] = $temp;
  20. }
  21. ksort($priceList);
  22. $temp = json_encode($priceList);
  23. echo $temp;
  24. foreach ($priceList as $key => $category) {
  25.  
  26. foreach ($category as $key=>$product) {
  27. $outputArr[$key] = $product['product'];
  28. }
  29.  
  30. array_multisort($outputArr, SORT_ASC, $category);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement