sagsoz06 / embed
媒体嵌入(适用于 Laravel 或独立使用)。
v5.3.1
2016-11-17 07:57 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.0
README
根据URL生成媒体HTML(YouTube、Vimeo、Kickstarter等)。
安装
将以下require添加到您的 composer.json
文件中
对于 Laravel 5
"cohensive/embed": "dev-master"
// or
"cohensive/embed": "5.0.*"
对于 Laravel 4
"cohensive/embed": "4.3.1"
然后运行 composer install
或 composer 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();
}