RRoEmbed is a PHP 5.3+ library that provides an interface to consume oEmbed resources.
oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.
Read more: oEmbed website
<?php
// Include the autoloader.
require_once( __DIR__ . '/Classes/Autoloader.class.php' );
// Register the autoloader.
RRoEmbed\Autoloader::getInstance()->register();
// Create a new consumer.
$consumer = new RRoEmbed\Consumer();
// Call the "consume" method and supply it the URL of the resource you'd like
// to get the oEmbed representation of and the Provider instance.
$resource = $consumer->consume(
'http://www.youtube.com/watch?v=ThvBJMzmSZI',
new RRoEmbed\Provider\YouTube()
);
// Will call __toString()
print $resource;
Result:
<object width="480" height="295"> […] </object>
// You can also omit to specify the provider, if so the Consumer will try to
// automatically find a valid provider endpoint.
// Note that, as the Consumer class implements the __invoke method you
// can use any of its instances as a callable.
$resource = $consumer( 'http://www.youtube.com/watch?v=ThvBJMzmSZI' );
print_r( $resource );
Result:
RRoEmbed\Resource\Video Object
(
[_html:protected] => <object width="480" height="295"><param name="movie" […]
[_width:protected] => 480
[_height:protected] => 295
[_type:protected] => video
[_version:protected] => 1.0
[_title:protected] => The Most AMAZING video on the internet #Egypt #jan25
[_authorName:protected] => hadi15
[_authorUrl:protected] => http://www.youtube.com/user/hadi15
[_providerName:protected] => YouTube
[_providerUrl:protected] => http://www.youtube.com/
[_cacheAge:protected] => 0
[_thumbnailUrl:protected] => http://i1.ytimg.com/vi/ThvBJMzmSZI/hqdefault.jpg
[_thumbnailWidth:protected] => 480
[_thumbnailHeight:protected] => 360
)
Copyright (c) 2012 Romain Ruetschi
Dual licensed under the MIT and GPL licenses.