Created
September 8, 2018 11:35
-
-
Save eto4detak/333471214c6734f974f32557ab269d95 to your computer and use it in GitHub Desktop.
youtybe php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $YoutubeCode = get_the_content(); | |
$YoutubeCode = 'https://youtu.be/COwlqqErDbY'; | |
$YoutubeCode = 'https://youtu.be/COwlqqErDbY'; | |
preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $YoutubeCode, $matches); | |
if (isset($matches[2]) && $matches[2] != '') { | |
$YoutubeCode = $matches[2]; | |
} | |
echo '<img src="http://img.youtube.com/vi/' . $YoutubeCode . '/0.jpg" />'; | |
echo '<iframe src="https://www.youtube.com/embed/'.$YoutubeCode.'" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment