cohensive/embed

媒体嵌入(适用于 Laravel 或作为独立应用程序)。

v5.6.0 2024-07-19 09:56 UTC

README

如果你正在运行 PHP 8+,我强烈推荐使用库的新版本:OEmbed
它具有更多功能,同时几乎以相同的方式工作。

嵌入

根据网址生成媒体 HTML(YouTube、Vimeo、Kickstarter 等)。

安装

将以下 require 添加到你的 composer.json 文件中

对于 Laravel 5

    "cohensive/embed": "dev-master"
    // or
    "cohensive/embed": "5.5.*"

对于 Laravel 4

    "cohensive/embed": "4.3.*"

然后运行 composer installcomposer update 来下载并自动加载它。

providers 数组中你需要添加一个新的包

'providers' => array(

	//...
	'Cohensive\Embed\EmbedServiceProvider',
	//...

)

在别名中

'aliases' => array(

	//...
	'Embed' => 'Cohensive\Embed\Facades\Embed'
	//...

)

使用方法

$embed = Embed::make('http://youtu.be/uifYHNyH-jA')->parseUrl();
// Will return Embed class if provider is found. Otherwie will return false - not found. No fancy errors for now.
if ($embed) {
	// Set width of the embed.
	$embed->setAttribute(['width' => 600]);

	// Print html: '<iframe width="600" height="338" src="//www.youtube.com/embed/uifYHNyH-jA" frameborder="0" allowfullscreen></iframe>'.
	// Height will be set automatically based on provider width/height ratio.
	// Height could be set explicitly via setAttr() method.
	echo $embed->getHtml();
}