简体   繁体   中英

How to get and print attributes in meta tags using simple_html_dom

Ok, I am at a loss here. I am new to programming, have Googled for this relentlessly, and have even asked about this here but to no avail, so I am trying again now that I am a little better researched.

I need to retrieve the text from what is inside the "content" attribute from this line of code:

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

This is the code that I have so far that is not working:

//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);

What I want that code to give me is:

title goes here

But instead I get a NULL error. I have a feeling a var_dump() is not actually what I want to be doing, but a simple echo() is returning errors also. I just have no idea what to do at this point, so any help would be GREATLY appreciated.

Thanks in advance!

尝试使用David Walsh编写的PHP Simple HTML DOM解析器... http://davidwalsh.name/php-notifications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM