メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

OEmbed::__construct

Get the oEmbed data of a URL

Description​

public OEmbed::__construct( string $url, [ array $config = array() ] )

Finds the service whose schemes match $url, requests its oEmbed endpoint and reads the embedded HTML. The result is available through the properties.

Throws an Exception when no service matches $url, the service has no endpoint, the request fails, or the response has no iframe, img or a element.

Arguments​

NameData typeDefaultRemarks
$urlstringURL of the page to embed
$configarrayarray()Options sent to the endpoint (see below)
KeyData typeDefaultRemarks
maxwidthintnullMaximum width of the embed
maxheightintnullMaximum height of the embed

Example​

Controller
use Fegg\Tool\OEmbed;

$oembed = new OEmbed('https://youtu.be/xxxxxxxxxxx', array('maxwidth' => 640));

echo $oembed->type; // -> "video"
echo $oembed->media; // -> "https://www.youtube.com/embed/xxxxxxxxxxx?feature=oembed"
echo $oembed->data['title']; // -> Video title