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.
All versions of embed with dependencies
Informations about the package embed
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).
- PHP 7.4+
- Curl library installed
- PSR-17 implementation. By default these libraries are detected automatically:
If you need PHP 5.5-7.3 support, use the 3.x version
This package is installable and autoloadable via Composer as embed/embed.
Parallel multiple requests
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
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
itemprop attributes and the value is get from
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:
Another API available by default, used to extract info using the JsonLD schema.
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:
Depending of your needs, you may want to extend this library with extra features or change the way it makes some operations.
Embed use some PSR standards to be the most interoperable possible:
- PSR-7 Standard interfaces to represent http requests, responses and uris
- PSR-17 Standard factories to create PSR-7 objects
- PSR-18 Standard interface to send a http request and return a response
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:
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 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.
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:
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
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:!