From d769253701956f50377cd264c7ae20203d273079 Mon Sep 17 00:00:00 2001 From: Yusuf Kandemir Date: Mon, 12 Nov 2018 11:20:01 +0300 Subject: [PATCH] Added different output methods --- src/MicrodataParser.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/MicrodataParser.php b/src/MicrodataParser.php index a65396b..a62ea89 100644 --- a/src/MicrodataParser.php +++ b/src/MicrodataParser.php @@ -14,6 +14,22 @@ class MicrodataParser $this->topLevelItems = $xpath->query('//*[@itemscope and not(@itemprop)]'); } + public function toArray() + { + // Somewhat hacky way to convert deep objects + return json_decode(json_encode($this->extractMicrodata()), true); + } + + public function toObject() + { + return $this->extractMicrodata(); + } + + public function toJSON($options = 0, $depth = 512) + { + return json_encode($this->extractMicrodata(), $options, $depth); + } + public function extractMicrodata() { $result = new \stdClass;