phphtmlparsingdomsimpledom

How to extract title and meta description using PHP Simple HTML DOM Parser?


How can I extract a page's title and meta description using the PHP Simple HTML DOM Parser?

I just need the title of the page and the keywords in plain text.


Solution

  • I just took a look at the HTML DOM Parser, try:

    $html = new simple_html_dom();
    $html->load_file('xxx'); //put url or filename in place of xxx
    $title = $html->find('title');
    echo $title->plaintext;
    
    $descr = $html->find('meta[description]');
    echo $descr->plaintext;