Skip to content

Commit

Permalink
Added check for existing key, if key already exists, the entry is cha…
Browse files Browse the repository at this point in the history
…nged to array. This way it supports multiple entries of the same key - namely image.
  • Loading branch information
GregersBoye authored and AramZS committed Jul 12, 2016
1 parent a76a50a commit 31e6e60
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions OpenGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,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.
Expand Down

0 comments on commit 31e6e60

Please sign in to comment.