Created
November 20, 2014 17:24
-
-
Save esedic/5b14e1ac92232c759513 to your computer and use it in GitHub Desktop.
Responsive youtube video embed with PHP
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | |
<title>Online PHP Script Execution</title> | |
<link href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet' type='text/css'> | |
<style> | |
body {padding: 1em;} | |
.video-container {position: relative;padding-bottom: 56.25%;padding-top: 30px;height: 0;overflow: hidden;} | |
.video-container iframe, .video-container object, .video-container embed {position: absolute;top: 0;left: 0;width: 100%;height: 100%;border: none;} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<?php | |
// define item | |
$videocode = '<iframe width="640" height="360" src="//www.youtube.com/embed/VazPRr8edZw" frameborder="0" allowfullscreen></iframe>'; | |
// array of strings which should be replaced | |
$before = array('<iframe', '</iframe>'); | |
// array of substitute strings | |
$after = array('<div class="video-container"><iframe', '</div></iframe>'); | |
// construct new item | |
$respvideo = str_replace($before, $after, $videocode); | |
// display responsive video | |
echo $respvideo; | |
?> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment