1

Sorry It might too simple question. However I can't find solution.

I try to find the OGP tag like this

<meta property="og:title" content="MyTitle" />
<meta property="og:type" content="MyProduct" /> 

I red PHP Simple HTML DOM Parser Manual and try very simple php script.

$html = str_get_html($source);
$meta = $html->find("meta[property=og:title]");
var_dump($meta->content);

It shows nothing. How can I get content??

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • `->find` always returns an array of elements. Use `var_dump($meta[0]->content);` – Dave Chen Sep 01 '16 at 02:15
  • 1
    Please don't use SimpleHTMLDom, there are vastly better options available ~ http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php – Phil Sep 01 '16 at 02:16
  • 1
    I'd try `$html->find('meta[property="og:title"]', 0)` to return the first object found instead of a collection. Also note the quotes around the attribute value – Phil Sep 01 '16 at 02:19
  • Thank you ,, your answer is quite correct. I made very beginner mistake. – whitebear Sep 01 '16 at 12:50

0 Answers0