yohacoo/ogp-info

Library for retrieving OGP information

Maintainers

Package info

github.com/yohacoo/ogp-info

pkg:composer/yohacoo/ogp-info

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-08-28 05:53 UTC

This package is not auto-updated.

Last update: 2026-03-27 08:22:35 UTC


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.