Skip to content

Instantly share code, notes, and snippets.

@jgb-solutions
Created April 11, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgb-solutions/ab01dcca5fbaa9c9cdc7 to your computer and use it in GitHub Desktop.
Save jgb-solutions/ab01dcca5fbaa9c9cdc7 to your computer and use it in GitHub Desktop.
Serving YouTube video dynamically with PHP
<?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