示例#1
0
 public function parseHtml()
 {
     $lines = explode(PHP_EOL, $this->html);
     $products['results'] = array();
     $total = 0;
     for ($i = 0; $i < count($lines); $i++) {
         if (strpos($lines[$i], "<div class=\"productInfo\"") !== false) {
             $product = array();
             $product["title"] = trim($lines[$i + 4]);
             $link = split('"', $lines[$i + 3]);
             $product["size"] = WebData::getSize($link[1]);
             $product["description"] = trim($lines[$i + 4]);
         } elseif (strpos($lines[$i], "<p class=\"pricePerUnit\">") !== false) {
             $unit_price = split("<", $lines[$i + 1]);
             $unit_price = substr($unit_price[0], 1);
             $product["unit_price"] = $unit_price;
             $total += $unit_price;
             $products['results'][] = $product;
         }
     }
     $products["total"] = $total;
     return $products;
 }
示例#2
0
 public function getSize($url)
 {
     $page = WebData::getContent($url);
     return round(strlen($page) / 1024, 2) . ' KB';
 }