您好,欢迎访问一九零五行业门户网

PHP网页实用小功能(一)

从网页中提取关键字
$meta = get_meta_tags('http://www.aseoe.com/');    $keywords = $meta['keywords'];    // split keywords    $keywords = explode(',', $keywords );    // trim them    $keywords = array_map( 'trim', $keywords );    // remove empty values    $keywords = array_filter( $keywords );         print_r( $keywords );  
效果如下
查找页面上的所有链接
使用dom,你可以轻松从任何页面上抓取链接,代码示例如下:
$html = file_get_contents('http://www.example.com');         $dom = new domdocument();    @$dom->loadhtml($html);         // grab all the on the page    $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.'
';    }    已测试 完全可以实现。
其它类似信息

推荐信息