Download the PHP package embed/embed without Composer

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

Please rate this library. Is it a good library?

All versions of embed with dependencies

Informations about the package embed

Embed

Latest Version on Packagist Total Downloads Monthly Downloads

PHP library to get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It's compatible with any web service (youtube, vimeo, flickr, instagram, etc) and has adapters to some sites like (archive.org, github, facebook, etc).

Requirements:

If you need PHP 5.5-7.3 support, use the 3.x version

Online demo

http://oscarotero.com/embed/demo

Installation

This package is installable and autoloadable via Composer as embed/embed.

Usage

Parallel multiple requests

Document

The document is the object that store the html code of the page. You can use it to extract extra info from the html code:

You can perform xpath queries in order to select specific elements. A search always return an instance of a Embed\QueryResult:

Metas

For convenience, the object Metas stores the value of all <meta> elements located in the html, so you can get the values easier. The key of every meta is get from the name, property or itemprop attributes and the value is get from content.

OEmbed

In addition to the html and metas, this library uses oEmbed endpoints to get additional data. You can get this data as following:

Additional oEmbed parameters (like instagrams hidecaption) can also be provided:

LinkedData

Another API available by default, used to extract info using the JsonLD schema.

Other APIs

Some sites like Wikipedia or Archive.org provide a custom API that is used to fetch more reliable data. You can get the API object with the method getApi() but note that not all results have this method. The Api object has the same methods than oEmbed:

Extending Embed

Depending of your needs, you may want to extend this library with extra features or change the way it makes some operations.

PSR

Embed use some PSR standards to be the most interoperable possible:

Embed comes with a CURL client compatible with PSR-18 but you need to install a PSR-7 / PSR-17 library. Here you can see a list of popular libraries and the library can detect automatically 'laminas\diactoros', 'guzzleHttp\psr7', 'slim\psr7', 'nyholm\psr7' and 'sunrise\http' (in this order). If you want to use a different PSR implementation, you can do it in this way:

Adapters

There are some sites with special needs: because they provide public APIs that allows to extract more info (like Wikipedia or Archive.org) or because we need to change how to extract the data in this particular site. For all that cases we have the adapters, that are classes extending the default classes to provide extra functionality.

Before creating an adapter, you need to understand how Embed work: when you execute this code, you get a Extractor class

The Extractor class has many Detectors. Each detector is responsible to detect a specific piece of info. For example, there's a detector for the title, other for description, image, code, etc.

So, an adapter is basically an extractor created specifically for a site. It can contains also custom detectors or apis. If you see the src/Adapters folder you can see all adapters.

If you create an adapter, you need also register to Embed, so it knows in which website needs to use. To do that, there's the ExtractorFactory object, that is responsible for instantiate the right extractor for each site.

Detectors

Embed comes with several predefined detectors, but you may want to change or add more. Just create a class extending Embed\Detectors\Detector class and register it in the extractor factory. For example:

Settings

If you need to pass settings to the CurlClient to perform http queries:

If you need to pass settings to your detectors, you can add settings to the ExtractorFactory:

Note: The built-in detectors does not require settings. This feature is only for convenience if you create a specific detector that requires settings.


If this library is useful for you, say thanks buying me a beer :beer:!


Version
Requires php Version ^7.4|^8
ext-curl Version *
ext-dom Version *
ext-json Version *
ext-mbstring Version *
composer/ca-bundle Version ^1.0
oscarotero/html-parser Version ^0.1.4
psr/http-message Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
ml/json-ld Version ^1.1

The package embed/embed contains the following files

Loading the files please wait ....