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
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-28