Salexes
Salexes

Reputation: 187

PHP - Simple HTML DOM Parser : content of <meta property=“og:description”

I'm trying to get the content of the meta tag "og:description" with the php code

if ($html->find('meta[property="og:description"]')!==null) 
{

    $post->excerpt = $html->find('meta[property="og:description"]')->content;   

} else {

  $post->excerpt = '';

}

The output is just:

["excerpt"]=> NULL

What I'm doing wrong ?

Upvotes: 2

Views: 1863

Answers (2)

Tama
Tama

Reputation: 311

I would better parse the html just one time and yes, as pguardiario says, you need to add 0 for index. The code:

$metaOgDescription = $html->find('meta[property="og:description"]', 0);
if ($metaOgDescription !== null) 
{
    $post->excerpt = $metaOgDescription->content;   
} else {
    $post->excerpt = '';
}

Upvotes: 1

pguardiario
pguardiario

Reputation: 55002

You need to add a 0 in there for the index:

$meta = $html->find($css, $index);

otherwise you get an array

Upvotes: 2

Related Questions