PHP 页面提取关键字和查找页面的所有链接 博客分类: 境-PHP2 PHP提取关键字PHP查找页面链接PHP
程序员文章站
2024-03-16 12:24:52
...
<meta charset="utf-8"> <?php $meta = get_meta_tags('http://onestopweb.iteye.com/blog/2330507'); $keywords = $meta['keywords']; $keywords = explode(',', $keywords); $keywords = array_map('trim', $keywords); $keywords = array_filter($keywords); print_r($keywords); ?>
效果图:
<meta charset="utf-8"> <?php $html = file_get_contents('http://onestopweb.iteye.com/'); $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); echo $url.'<br />'; } ?>
效果图: