如何使用simple_html_dom获取和打印元标记中的属性


How to get and print attributes in meta tags using simple_html_dom

好的,我在这里不知所措。我是编程新手,一直在谷歌上搜索,甚至在这里询问过这件事,但都无济于事,所以我现在又在尝试,因为我的研究有点深入了。

我需要从这行代码的"内容"属性中检索文本:

<meta property='og:title' content="title goes here" />

这是我迄今为止没有工作的代码:

//saves the URL as HTML
$movie_html = file_get_html($movie_url);
//finds the title within the HTML
$movie_title_meta = $movie_html->find("meta[name=og:title]");
$movie_title = $movie_title_meta->content;
//prints the score
var_dump($movie_title_meta);

我想让这个代码给我的是:

title goes here

但是我得到了一个NULL错误。我有一种感觉,var_dump()实际上不是我想要做的,但简单的echo()也会返回错误。我只是不知道在这一点上该做什么,所以任何帮助都将不胜感激。

提前感谢!

尝试使用David Walsh的PHP Simple HTML DOM Parser。。。http://davidwalsh.name/php-notifications