我有这个控制器,在youtube,vimeo,vevo等中存储视频的主机和网址
public function attach()
{
$input = Input::except('_token');
if ( ! Input::get('host') || ! Input::get('url')) {
return Response::json(trans('video::main.fillAllRequiredFields'), 400);
}
}
在刀片上我有这个
@foreach ($title->link as $k => $video)
<p><a target="_blank" href="{{ $video->url }}">{{ $video->host }}</a></p>
@endforeach
现在,成员必须插入主机的url和标签。
我想在Laravel或knockout.js中使用一个函数,所以当插入一个url来提取主机并自动显示主机标签而不存储在DB中。像这样的东西
@foreach ($title->link as $k => $video)
@if {{$video->url}} contain "youtube.com"
<p><a target="_blank" href="{{ $video->url }}">YouTube</a>
@elseif {{$video->url}} contain "vimeo.com"
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
@elseif {{$video->url}} contain "vevo.com"
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
@else <p><a target="_blank" href="{{ $video->url }}">Unknown</a>
@endif
@endforeach
非常感谢任何帮助
答案 0 :(得分:1)
PHP函数strpos()允许您检查url字符串是否包含特定主机。例如像这样
@foreach ($title->link as $k => $video)
@if(strpos($video->url, "youtube.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">YouTube</a>
@if(strpos($video->url, "vimeo.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">Vimeo</a>
@if(strpos($video->url, "vevo.com")!==false)
<p><a target="_blank" href="{{ $video->url }}">Vevo</a>
@else <p><a target="_blank" href="{{ $video->url }}">Unknown</a>
@endif
@endforeach