承接 yohacoo/ogp-info 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yohacoo/ogp-info

最新稳定版本:v1.0.0

Composer 安装命令:

composer require yohacoo/ogp-info

包简介

Library for retrieving OGP information

README 文档

README

Library for retrieving OGP information via HTTP/HTTPS.

Install

composer require yohacoo/ogp-info

Or simply copy src/OgpInfo.php to your project.

Usage

require_once('OgpInfo.php');

use Yohacoo\OgpInfo\OgpInfo;

OgpInfo::setCacheDir('/path/to/.ogp-cache');
$info = OgpInfo::retrieve('https://example.com/');

$title = $info->get('og:title', 'title');
$description = $info->get('og:description', 'description');

We strongly recommend setting a cache directory. The default cache directory is .ogp-cache under the directory containing OgpInfo.php.

API

OgpInfo->get(...$keys)

Get the first non-empty value for keys. If no value exists for the keys, return an empty string ('').

Key Description
og:xxx og:xxx value in <meta property="og:xxx" content="...">
fb:xxx fb:xxx value in <meta property="fb:xxx" content="...">
twitter:xxx twitter:xxx value in <meta name="twitter:xxx" content="...">
title <title> tag text content
description description value in <meta name="description" content="...">
icon href value in <link rel="icon" href="...">
Return the absolute URL if the href starts with '/'.
apple-touch-icon href value in <link rel="apple-touch-icon" href="...">
Return the absolute URL if the href starts with '/'.

OgpInfo->getUrl()

Get URL for retrieving information.

OgpInfo->getHttpStatus()

Get HTTP status code.

OgpInfo->getTimestamp()

Get timestamp. Returns the number of seconds since the epoch.

OgpInfo->isExpired()

Check whether it has passed the TTL.

Static API

OgpInfo::setCacheDir($dir)

Set the cache directory.

OgpInfo::retrieve($url)

Retrieve OGP information via HTTP.

OgpInfo::setCacheTtl($ttl)

Set the cache TTL.

OgpInfo::clearCache()

Delete old cache files.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-28