search
Homephp教程php手册PHP网页实用小功能(一)


从网页中提取关键字

  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.'
    '
    ;   
  14. }   

已测试 完全可以实现。



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft