Skip to content

Instantly share code, notes, and snippets.

@RuslanAsadov
Last active December 5, 2020 18:55
Show Gist options
  • Save RuslanAsadov/5f9995827562a497400f2003d1112f23 to your computer and use it in GitHub Desktop.
Save RuslanAsadov/5f9995827562a497400f2003d1112f23 to your computer and use it in GitHub Desktop.
youtube-video.sass
.video {
position: relative;
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
.video iframe {
border: none;
position: absolute;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
}
<div class="video"><iframe src="https://www.youtube.com/embed/iNPE0zGucTo" allowfullscreen></iframe></div>
<?php
// Типы превью
// http://shpargalkablog.ru/2013/06/youtube.html
// Если iframe
$iframe_video = (string) trim(get_field('youtube'));
preg_match( '/[^>]*src *= *["\']?([^"\']*)/i', $iframe_video, $matches );
$video_src = $matches[1];
$params = parse_url($video_src);
$code_video = explode('/', $params['path'])[2];
// Если ссылка на ролик
$params = parse_url(get_field('link'));
parse_str($params['query'], $query);
$link = explode('/', $params['path'])[2];
$query['v'];
//Универсальный вариант
$subject = "http://www.youtube.com/watch?v=z_AbfPXTKms&NR=1";
preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $subject, $matches);
$matches[1];
.video
position: relative
padding-bottom: 56.25%
padding-top: 25px
height: 0
iframe
border: none
position: absolute
top: 0
left: 0
width: 100% !important
height: 100% !important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment