} } class HtmlElements { protected $elements = array(); /** * addChild elements to the collection * * @param DOMElement $elementCode */ public function addChild($element) { $this->elements[] = $element; } /** * getElements method - get element collection found in the source * * @return int */ public function count() { return count($this->elements); } } try { $dom = new HtmlParser('http://www.bbc.com/'); $elements = $dom->getElements('div'); echo $elements->count(); } catch (Exception $e) { echo $e->getMessage(); }