Download the PHP package osmuhin/html-meta without Composer

On this page you can find all versions of the php package osmuhin/html-meta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package html-meta

HTML meta logo

Tests status Coverage Total Downloads License

HTML Meta is a PHP package for parsing website metadata, such as titles, favicons, Open Graph tags, JSON-LD and others.


Installation

To install the package via Composer, run:

[!NOTE] Ensure that the vendor/autoload.php file is required in your code to enable the autoloading mechanism provided by Composer.

Basic usage

Parsing Metadata from URL

Parsing Metadata from Raw HTML

Instead of URL, you can parse metadata from Raw HTML passing it as a string:

Always pass the url parameter when using raw HTML to resolve relative paths correctly.

Relative URL resolution follows RFC 3986: a base without a trailing slash treats the last path segment as a file. Use a trailing slash (e.g. https://example.com/dir/) when the base should act as a directory.

Using a Custom Request Object

Under the hood, the GuzzleHttp library is used to get html, so you can create your own request object and pass it as a $request parameter:

[!WARNING] When crawling URLs from untrusted input, be aware of SSRF risks (the crawler follows redirects by default). Prefer injecting a hardened Guzzle client via setGuzzleClient() (timeouts, allowlists, disabled private networks) instead of passing raw user URLs to Crawler::init(url: ...).

All properties of the meta object are described here.

Extended Open Graph namespaces

The crawler supports extended Open Graph namespaces in addition to base og:* tags:

Unknown base og:* keys are preserved in $meta->openGraph->other.

JSON-LD

The crawler collects every <script type="application/ld+json"> tag (in head or body).

Invalid JSON is kept in scripts with valid = false and does not produce nodes. Node url is resolved like other URLs unless dontProcessUrls() is set.

Configuration

You can customize the crawler’s behavior using its configuration methods:

Setting Description
Disables the conversion of relative URLs to absolute URLs.
Disables automatic type conversions (e.g., string to int):


Using type conversions:
Disabled type conversions:


Using type conversions: null
Disabled type conversions:
Sets a base URL for resolving relative paths (automatically enables URL processing).
Disables the default distributor configuration.

Core concepts

The Crawler object

The main interaction happens through the $crawler object of type \Osmuhin\HtmlMeta\Crawler.

  1. Initialization: Configure the crawler before run() calling.

  2. Execution: After run() calling, the crawler performs the following steps:

    • fetches the HTML string from the URL (if raw HTML is not provided).
      The priority of the parameters, if they are more than 1 is following: string $html ➡ \GuzzleHttp\Psr7\Request $request ➡ string $url;

    • parses the HTML using the configured xpath:

      You are free to overwrite xpath property;

    • passes the parsed elements to the distributor stack;

    • the found HTML element is passed to the distributor stack
      If the HTML element passed the conditions, then its value is written to DTO (Data Transfer Object) of the type \Osmuhin\HtmlMeta\Contracts\Dto;

    • after parsing the HTML string, the root DTO \Osmuhin\HtmlMeta\Dto\Meta is formed in output.

Distributors

A Distributor validates HTML elements and distributes their data into DTOs.

Distributor must implement the interface \Osmuhin\HtmlMeta\Contracts\Distributor and has 2 main methods:

You can view the structure of the simplest TitleDistributor distributor:

You are free to replace some kind distributor of your own, example:

replace original TitleDistributor in initial configuration:

... or even overwrite the distributors tree completely:

Default distributors configuration

Contributing

Thank you for considering contributing to this package! Please refer to the Contributing Guidelines for more details.

You can contact me or just come say hi in Telegram: @wischerdson

License

This package is open-sourced software licensed under the MIT license.


All versions of html-meta with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-mbstring Version *
guzzlehttp/guzzle Version >=6.3
guzzlehttp/psr7 Version >=1.8
masterminds/html5 Version >=2.8
symfony/dom-crawler Version >=6.0
symfony/mime Version >=6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package osmuhin/html-meta contains the following files

Loading the files please wait ...