shevabam/php-extract-meta-url

从URL提取标题、描述、关键词、图片、favicon和RSS

1.0.4 2023-03-25 16:55 UTC

This package is auto-updated.

Last update: 2024-09-25 20:10:54 UTC


README

PHP Extract Meta URL 是一个非常简单的库,允许从网站的URL中获取各种信息

  • 标题
  • 描述
  • 关键词
  • 图片
  • favicon
  • RSS源

要求

  • PHP 7.4+
  • PHP cURL扩展
  • PHP json扩展

安装

使用Composer,运行以下命令

composer require shevabam/php-extract-meta-url

用法

简单示例

<?php
require 'vendor/autoload.php';

$url = 'https://www.gadgets360.com/science/news/blue-origin-jeff-bezos-new-shepard-ns-23-nasa-3339832';

$x = new \PhpExtractMetaUrl\PhpExtractMetaUrl($url);
$x->setFormat('array'); // default: json
$result = $x->extract();

echo '<pre>';
print_r($result);

返回值

Array
(
    [website] => Array
        (
            [url] => https://www.gadgets360.com/science/news/blue-origin-jeff-bezos-new-shepard-ns-23-nasa-3339832
            [scheme] => https
            [host] => www.gadgets360.com
        )

    [title] => Blue Origin Rocket Fails Shortly After Lift-Off: All Details | Technology News
    [description] => A Blue Origin rocket has failed mid-flight shortly after its lift-off a day ago. This has caused the rocket to abort its cargo capsule to safety before crashing into the Texas desert. The rocket aimed to send NASA-funded experiments and other payloads to the edge of the space. The booster crashed within the designated hazard area.
    [keywords] => Array
        (
            [0] => blue origin jeff bezos new shepard ns 23 nasa blue origin
            [1] => nasa
            [2] => jeff bezos
            [3] => new shepard
        )

    [image] => https://i.gadgets360cdn.com/large/blue_moon_bezos_reuters_1624520858507.jpg
    [favicon] => https://www.gadgets360.com/favicon.ico
    [rss] => Array
        (
            [0] => https://feeds.feedburner.com/gadgets360-latest
        )

)