Created
April 11, 2015 21:39
-
-
Save jgb-solutions/ab01dcca5fbaa9c9cdc7 to your computer and use it in GitHub Desktop.
Serving YouTube video dynamically with 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 | |
if ( isset( $_GET['submit'] ) && !empty( $_GET['youtubeID'] ) ) { // check whether the form has been submitted | |
$youtubeID = $_GET['youtubeID']; // storing the ID in a variable | |
$embedCode = '<iframe width="854" height="510" src="https://www.youtube.com/embed/' . $youtubeID . '" frameborder="0" allowfullscreen></iframe>'; // YouTube Embed code template | |
} else { | |
$embedCode = 'Enter an ID in the form above'; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang=""> | |
<head> | |
<meta charset="utf8"> | |
<title>Your Default title</title> | |
</head> | |
<body> | |
<h1>Add a new YouTube video</h1> | |
<form action="youtube-video.php" method="get"> | |
<label for="youtubeID">ID of YouTube's video : | |
<input type="text" name="youtubeID" id="youtubeID" placeholder="Please paste your YouTube video's ID" > | |
</label> | |
<input type="submit" name="submit" value="Submit" > | |
</form> | |
<h2>Your video</h2> | |
<?php echo $embedCode; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment