CEinNYC Posted October 22, 2010 Share Posted October 22, 2010 Hey all - Below is my code. I'm uncertain how to move correctly code (syntax) what I'm looking to do.. When the user clicks "Next" or "Previous," the following youtube clip will load into the div tag. (With the corresponding description tag). Where do I incorporate the str_replace? And how do I make sure both the youtube clip with the correct description is loaded? Any advice is appreciated! <?php $youtubeIds = array("rHNtuaVHenM","zIAdbIMNq9g","QQ4TlJLa-n4","JccPOA12ELI","JccPOA12ELI", "TWhhXVqVB7E"); $embedCode = '<object width="853" height="505"><param name="movie" value="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object>'; if(isset($_GET['youtubeclip'])) { if(is_numeric($_GET['youtubeclip'])) { if($_GET['youtubeclip'] >= 0 && $_GET['youtubeclip'] <= 5) { $youtubeclip = $_GET['youtubeclip']; } else { $youtubeclip = 0; } } else { $youtubeclip = 0; } $prevyoutubeclip = $youtubeclip-1; if($prevyoutubeclip < 0) { $prevyoutubeclip = 5; } $nextyoutubeclip = $youtubeclip+1; if($nextyoutubeclip > 5) { $nextyoutubeclib = 0; } $clip_names= array('Episode #1', 'Episode #2', 'Episode #3', 'Episode #4', 'Episode #5', 'Episode #6'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Billy Green</title> <link rel="stylesheet" type="text/css" media="screen" href="episode_style.css"> </head> <body> <div class="wrapper"> <?php include 'header.php'?> <div id="episode_content"> <div class="youtube_box"> <?php echo $embedCode; ?> </div> <h2 class="clip-description">"<?php echo $clip_names[$youtubeclip]; ?>" </h2> <div class="youtube_control"> <a href="episodes.php?youtubeclip=<?php echo $prevyoutubeclip; ?>"> Previous Clip </a> <a href="episodes.php?youtubeclip=<?php echo $nextyoutubeclip; ?>"> Next Clip </a> </div> </div> <div class="clearIt"> </div> <?php include 'footer.php'?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/ Share on other sites More sharing options...
savagenoob Posted October 22, 2010 Share Posted October 22, 2010 Ew that is messy... First, when entering html into a PHP variable, you need to escape all " with a /. And in forums, use the PHP button (above) when pasting code so we can read it better. Sooooo.... $embedCode = '<object width="853" height="505"><param name="movie" value="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object>'; Would be.... $embedCode = "<object width=/"853/" height=/"505/"><param name=/"movie/" value=/"http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US/"></param><param name=/"allowFullScreen/" value=/"true/"></param><param name=/"allowscriptaccess/" value=/"always/"></param><embed src=/"http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US/" type=/"application/x-shockwave-flash/" allowscriptaccess=/"always/" allowfullscreen=/"true/" width=/"853/" height=/"505/"></embed></object>"; Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125105 Share on other sites More sharing options...
Colton.Wagner Posted October 22, 2010 Share Posted October 22, 2010 Savagenoob it suppose to be a \ not a / and please use code tags. Thanks, Colton Wagner Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125118 Share on other sites More sharing options...
CEinNYC Posted October 22, 2010 Author Share Posted October 22, 2010 Okay, will do regarding appropriate syntax. (I should read the rules!) Thanks for of this... Sooooo.. How do I incorporate the youtube clip, into the emded code, and have the operation work with the "next" and "previous" buttons? (With the corresponding description tag). I'm sure this is a moronic question regarding accessing arrays but, it's where I am right now. Thanks again! Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125225 Share on other sites More sharing options...
Colton.Wagner Posted October 22, 2010 Share Posted October 22, 2010 So basically you did not set your array in the header your code is messed up. I will attempt to change it later I am on my blackberry right now but here is some of it corrected see if it works. <?php $youtubeIds = array("rHNtuaVHenM","zIAdbIMNq9g","QQ4TlJLa-n4","JccPOA12ELI","JccPOA12ELI", "TWhhXVqVB7E"); $embedCode = '<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/' . $youtubeIds['$youtubeclip'] .'?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $youtubeIds['$youtubeclip'] .'?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object>'; if(isset($_GET['youtubeclip'])) { if(is_numeric($_GET['youtubeclip'])) { if($_GET['youtubeclip'] >= 0 && $_GET['youtubeclip'] <= 5) { $youtubeclip = $_GET['youtubeclip']; } else { $youtubeclip = 0; } } else { $youtubeclip = 0; } $prevyoutubeclip = $youtubeclip-1; if($prevyoutubeclip < 0) { $prevyoutubeclip = 5; } $nextyoutubeclip = $youtubeclip+1; if($nextyoutubeclip > 5) { $nextyoutubeclib = 0; } $clip_names= array('Episode #1', 'Episode #2', 'Episode #3', 'Episode #4', 'Episode #5', 'Episode #6'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Billy Green</title> <link rel="stylesheet" type="text/css" media="screen" href="episode_style.css"> </head> <body> <div class="wrapper"> <?php include 'header.php'?> <div id="episode_content"> <div class="youtube_box"> <?php echo $embedCode; ?> </div> <h2 class="clip-description">"<?php echo $clip_names[$youtubeclip]; ?>" </h2> <div class="youtube_control"> <a href="episodes.php?youtubeclip=<?php echo $prevyoutubeclip; ?>"> Previous Clip </a> <a href="episodes.php?youtubeclip=<?php echo $nextyoutubeclip; ?>"> Next Clip </a> </div> </div> <div class="clearIt"> </div> <?php include 'footer.php'?> </div> </body> </html> Tell me what happens. Thanks, Colton Wagner Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125296 Share on other sites More sharing options...
CEinNYC Posted October 22, 2010 Author Share Posted October 22, 2010 Many thanks for your help! With that change to the embed code, here is the error: Undefined index: $youtubeclip on line 3. $youtube is defined later in the php. hmmm... mmmm..mmm. Thank you! Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125316 Share on other sites More sharing options...
Colton.Wagner Posted October 22, 2010 Share Posted October 22, 2010 Did you get it all solved? Thanks, Colton Wagner Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125318 Share on other sites More sharing options...
CEinNYC Posted October 22, 2010 Author Share Posted October 22, 2010 I did not, rather I got the error: Undefined index: $youtubeclip, on line 3. Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125321 Share on other sites More sharing options...
CEinNYC Posted October 23, 2010 Author Share Posted October 23, 2010 bump. still no luck. Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125596 Share on other sites More sharing options...
PaulRyan Posted October 23, 2010 Share Posted October 23, 2010 There are 2 methods that I can think of for this. 1 - Use JavaScript to change the youtube URL's - No page reload 2 - Use PHP with a GET variable from the URL - Requires page reload If you tell me what sort of thing your looking for I'm sure I could come up with something. I have made something like this in the past, I used a mix of both to get a good result. My version also automatically moved to the next song/video when the video had finished and would loop if it had come to the end of the array of songs/videos. Regards, Paul. Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125599 Share on other sites More sharing options...
CEinNYC Posted October 23, 2010 Author Share Posted October 23, 2010 Thanks for this.. ! Below is the link to the site (in progress). The box on the left has an embedded youtube object code. As the user clicks "next" or "previous" the corresponding video loads. The youtubeIds are in an array, and I assume that I need to use "str_replace," however I am unable to connect the "next/previous" buttons, with both the video description and the youtubeId array. Because of the restraints of the assignment, I need to keep it solely to php. Thanks for any advice! I assume there's a small php function that will solve all my problems (in both life and this assignment). Please excuse the sloppy site. It's in progress. Link: http://a.parsons.edu/~eckec706/temp/episodes.php (you may need to click "next" to pull up the first video.. Another issue, but I'll leave that for another time). Code attached. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125607 Share on other sites More sharing options...
PaulRyan Posted October 23, 2010 Share Posted October 23, 2010 So it has to be done in solely PHP, well that should be quite simple to do in theory. Are the arrays hard-coded or are they dynamic, as in change depending on a variable. If you give me the array you are working with I will muster something up for you Regards, Paul. Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125608 Share on other sites More sharing options...
CEinNYC Posted October 23, 2010 Author Share Posted October 23, 2010 Thanks! I'll have to pay this forward when I'm a php wiz. Here's the php.. Note "__YOUTUBE_ID__" is to indicate where to place the .str_replace. At the end of the php is the html function. <?php $youtubeIds = array("rHNtuaVHenM","zIAdbIMNq9g","QQ4TlJLa-n4","JccPOA12ELI","JccPOA12ELI", "TWhhXVqVB7E"); $embedCode = '<object width="640" height="385"><param name="movie" value="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/watch?v=__YOUTUBE_ID__?fs=1&hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>'; if(isset($_GET['youtubeclip'])) { if(is_numeric($_GET['youtubeclip'])) { if($_GET['youtubeclip'] >= 0 && $_GET['youtubeclip'] <= 5) { $youtubeclip = $_GET['youtubeclip']; } else { $youtubeclip = 0; } } else { $youtubeclip = 0; } $prevyoutubeclip = $youtubeclip-1; if($prevyoutubeclip < 0) { $prevyoutubeclip = 5; } $nextyoutubeclip = $youtubeclip+1; if($nextyoutubeclip > 5) { $nextyoutubeclib = 0; } $clip_names= array('Episode #1', 'Episode #2', 'Episode #3', 'Episode #4', 'Episode #5', 'Episode #6'); } ?> ------------------------------------ <div class="youtube_box"> <?php echo $embedCode ?> <div class="clip-description"><h2> <?php echo $clip_names[$youtubeclip]; ?> </h2></div> <div class="youtube_buttons_previous"><a href="episodes.php?youtubeclip=<?php echo $prevyoutubeclip; ?>"><img src="img/main/previous.png" border="0" width="184" height="81" alt="previous"/></a></div> <div class="youtube_buttons_next"><a href="episodes.php?youtubeclip=<?php echo $nextyoutubeclip; ?>"><img src="img/main/next.png" border="0" width="101" height="79" alt="next"/></a></div> </div> <div class="bgphoto"><img src="img/video/bg.png" width="" height="" alt="Billy Green"/> </div> Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125611 Share on other sites More sharing options...
PaulRyan Posted October 23, 2010 Share Posted October 23, 2010 I have just written the following code for you to use, I have supplied sufficent information and comments. Now it's up to you to use the script accordingly <?PHP // Function to retrieve data from video information file. function getData($string,$oTag,$cTag) { $start = strpos($string, $oTag); $end = strpos($string, $cTag, ($start + strlen($oTag))); $start = ($start + strlen($oTag)); $end = ($end - $start); return substr($string, $start, $end); } // Function to get and set information about the current episode function currentEpisode($youtubeURL) { $stats = 'http://gdata.youtube.com/feeds/api/videos/'.$youtubeURL; $stats = file_get_contents($stats); $videoURL = 'http://www.youtube.com/v/'.$youtubeURL; $videoDes = getData($stats,"<media:description type='plain'>","</media:description>"); $videoTtl = getData($stats,"<title type='text'>","</title>"); $information = array("title"=>$videoTtl, "description"=>$videoDes, "URL"=>$videoURL); return $information; } // Function to set the next link function nextLink($num,$count) { if($num == $count) { $nextLink = 1; } else if($num+1 > $count) { $nextLink = 1; } else { $nextLink = $num+1; } return $nextLink; } // Function to set the previous link function prevLink($num) { if($num-1 <= 1) { $prevLink = 1; } else { $prevLink = $num-1; } return $prevLink; } // Place episodes in an array $episodes = array("1"=>"rHNtuaVHenM","zIAdbIMNq9g","QQ4TlJLa-n4","JccPOA12ELI","JccPOA12ELI", "TWhhXVqVB7E"); // Count the number of episode $countEpisodes = count($episodes); // If $_GET['episode'] is a number we'll set the variable, otherwise set as first episode. if(is_numeric($_GET['episode'])) { $currentEpisode = $_GET['episode']; } else { $currentEpisode = 1; } // If the current episode number is greater than episode count, set episode as last. if($currentEpisode > $countEpisodes) { $currentEpisode = $countEpisodes; } // If the current episode mumber is less than 1, set the episode as 1 if($currentEpisode < 1) { $currentEpisode = 1; } $nextLink = '<input onClick="window.location=\'?episode='. nextLink($currentEpisode,$countEpisodes) .'\';" type="button" name="next" value=">>">'; $prevLink = '<input onClick="window.location=\'?episode='. prevLink($currentEpisode) .'\';" type="button" name="prev" value="<<">'; // Get the information for current episode selected $thisEpisode = currentEpisode($episodes[$currentEpisode]); // Set the episode URL for embed $thisURL = $thisEpisode['URL']; // Set the episode description $thisDes = nl2br($thisEpisode['description']); // Set the episode title $thisTtl = $thisEpisode['title']; echo '<pre>'; print_r($thisEpisode); echo '</pre>'; echo $prevLink; echo $nextLink; ?> Tell me how you get on with it. Regards, Paul. Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125619 Share on other sites More sharing options...
CEinNYC Posted October 23, 2010 Author Share Posted October 23, 2010 Thanks so much for this. I'll take a good look through and figure out what's going.. (Upon initially looking, there's lots of new "Stuff" there for me to learn). I'll let you know how it goes. Thanks! Link to comment https://forums.phpfreaks.com/topic/216524-youtube-php-embed-help-noob-alert/#findComment-1125621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.