CodeIgniter: A Class/Library to help get meta tags from a web page?

后端 未结 5 1768
日久生厌
日久生厌 2020-12-01 22:59

I am using codeigniter. I guess it doesn\'t matter which php framework I am using.

But before I write my own class is there another that has already been written tha

相关标签:
5条回答
  • 2020-12-01 23:27

    Use PHP's curl library. It can pull other pages from the web and fetch them as strings, and then you can parse the string with regular expressions to find the page's title and meta tags.

    0 讨论(0)
  • 2020-12-01 23:27

    With DOM/xpath

    libxml_use_internal_errors(true);
    $c = file_get_contents("http://url/here");
    $d = new DomDocument();
    $d->loadHTML($c);
    $xp = new domxpath($d);
    foreach ($xp->query("//meta[@name='keywords']") as $el) {
        echo $el->getAttribute("content");
    }
    foreach ($xp->query("//meta[@name='description']") as $el) {
        echo $el->getAttribute("content");
    }
    
    0 讨论(0)
  • 2020-12-01 23:34

    You can get all the meta tags froma remote page with get_meta_tags - http://ca3.php.net/get_meta_tags

    this page has a class to get the page and description, they are also using get_meta_tags - http://www.emirplicanic.com/php/get-remote-page-title-with-php.php

    You should be able to combine bits from both to get everything you need.

    0 讨论(0)
  • 2020-12-01 23:36

    You should have a look at this class: PHP Simple HTML DOM it works this way:

    include('simple_html_dom.php');
    $html = file_get_html('http://www.codeigniter.com/');
    
    echo $html->find('title', 0)->innertext; // get <title>
    
    echo "<pre>";
    foreach($html->find('meta') as $element)
           echo $element->name . " : " . $element->content  . '<br>'; //prints every META tag
    
    echo "</pre>";
    
    0 讨论(0)
  • 2020-12-01 23:47

    See this please. This is generic class to get page meta tags and do a lot more. See if you can add this in codeigniter library. Thanks

    0 讨论(0)
提交回复
热议问题