From bf39304ae5a2052b2738f186913c6707a4133372 Mon Sep 17 00:00:00 2001 From: Gregers Boye-Jacobsen Date: Thu, 8 Oct 2015 18:15:02 +0200 Subject: [PATCH] Added check for existing key, if key already exists, the entry is changed to array. This way it supports multiple entries of the same key - namely image. --- OpenGraph.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/OpenGraph.php b/OpenGraph.php index af2e7b6..76bb968 100644 --- a/OpenGraph.php +++ b/OpenGraph.php @@ -96,10 +96,18 @@ static private function _parse($HTML) { $nonOgDescription = null; foreach ($tags AS $tag) { - if ($tag->hasAttribute('property') && - strpos($tag->getAttribute('property'), 'og:') === 0) { + if ($tag->hasAttribute('property') && strpos($tag->getAttribute('property'), 'og:') === 0) { $key = strtr(substr($tag->getAttribute('property'), 3), '-', '_'); - $page->_values[$key] = $tag->getAttribute('content'); + + if(isset($key)){ + if(!is_array($page->_values[$key])){ + $temp = $page->_values[$key]; + $page->_values[$key] = array($temp); + } + $page->_values[$key][] = $tag->getAttribute('content'); + }else{ + $page->_values[$key] = $tag->getAttribute('content'); + } } //Added this if loop to retrieve description values from sites like the New York Times who have malformed it.