PHP网页实用小功能(一)

导语 从网页中提取关键字$meta=get_meta_tags(& 39;http: www aseoe com & 39;);$keywords=$meta[& 39;keywords& 39;]; Splitkeywords$keywords=explode(& 39;,& 39;,$keywords); Trimthem$keywords=array_map(& 3

从网页中提取关键字

  1. $meta = get_meta_tags('http://www.aseoe.com/');   
  2. $keywords = $meta['keywords'];   
  3. // Split keywords   
  4. $keywords = explode(','$keywords );   
  5. // Trim them   
  6. $keywords = array_map'trim'$keywords );   
  7. // Remove empty values   
  8. $keywords = array_filter$keywords );   
  9.     
  10. print_r( $keywords );  


效果如下

\

查找页面上的所有链接

使用DOM,你可以轻松从任何页面上抓取链接,代码示例如下: 

 

  1. $html = file_get_contents('http://www.example.com');   
  2.     
  3. $dom = new DOMDocument();   
  4. @$dom->loadHTML($html);   
  5.     
  6. // grab all the on the page   
  7. $xpath = new DOMXPath($dom);   
  8. $hrefs = $xpath->evaluate("/html/body//a");   
  9.     
  10. for ($i = 0; $i < $hrefs->length; $i++) {   
  11.        $href = $hrefs->item($i);   
  12.        $url = $href->getAttribute('href');   
  13.        echo $url.'<br />';   
  14. }   

已测试 完全可以实现。

http://www.aseoe.com/ true PHP网页实用小功能(一) http://www.aseoe.com/show-21-324-1.html report <?php echo strlen($content) / 2; ?> 从网页中提取关键字$meta=get_meta_tags(& 39;http: www aseoe com & 39;);$keywords=$meta[& 39;keywords& 39;]; Splitkeywords$keywords=explode(& 39;,& 39;,$keywords); Trimthem$keywords=array_map(& 3
TAG:PHP 功能 网页
本站欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明: 文章转载自:爱思资源网 http://www.aseoe.com/show-21-324-1.html

[前端插件推荐] Plugin

1 2 3 4
  • jQuery实现逐字逐句显示插件l-by-l.min.js
  • jQuery带方向感知的鼠标滑过图片边框特效插件
  • jQuery HotKeys监听键盘按下事件keydown插件
  • 响应式无限轮播jQuery旋转木马插件
响应式无限轮播jQuery旋转木马插件
web前端开发
爱思资源网 Copyright 2012-2014 Www.Aseoe.Com All rights reserved.(晋ICP备13001436号-1)