cyberhost Posted September 7, 2011 Share Posted September 7, 2011 Hi, Ok so I have the youtube url input working and it shows the video fine have a look at http://www.cyberhost.me/test But now what I need is for the script to display the embed code needed for the user. This is the script: <?php $text = $_POST["text"]; if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <html> <head> <title>Youtube code generator</title> </head> <body> <p>Copy and paste this url for example: http://www.youtube.com/watch?v=YdDIsImNfBY&feature</p><br/><br/> <form method="post" action="<?php echo $PHP_SELF;?>"> Youtube URL:<input type="text" size="50" maxlength="50" name="text"><br /> <input type="submit" value="submit" name="submit"> </form> <?php } else { //space anything that would get included in a link, add the space $text = str_ireplace(array("<br />","\n","\r"),array(" <br /> "," \n "," \r "),$text); $text = str_replace(" ", " ", $text); //explode the text by spaces $text_explode = explode(" ",$text); //loop replacing youtube links with embed codes, if not youtube embed return text foreach($text_explode as $words){ if (preg_match('~(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})~i', $words, $match)) { $vidid = $match[1];//the id $link = "http://youtu.be/$vidid";//short link to video //grab the title $visit_url = "http://gdata.youtube.com/feeds/api/videos/".$vidid; $doc = new DOMDocument; @$doc->load($visit_url); $link_title = $doc->getElementsByTagName("title")->item(0)->nodeValue; if($link_title == ""){ $link_title = "Click to watch video."; } //display a link echo "<h3><a href='$link' TARGET='_blank'>$link_title</a></h3>"; //embed the video echo "<div>"; echo "<object style='height: 390px; width: 640px'> <param name='movie' value='http://www.youtube.com/v/$vidid&fs=1'> <param name='allowFullScreen' value='true'> <param name='allowScriptAccess' value='always'> <embed src='http://www.youtube.com/v/$vidid&fs=1' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'></object>"; echo "</div><br />"; } else { //keep the original words echo " $words "; } } } ?> The code I need displayed below is <p> <img height="350" width="425" class="fw_media_youtube fw-parse" alt="YouTube-CODE PLACED HERE" src="http://thumbs.webs.com/Platform/mediaPreview.jsp?type=YouTube&id=CODE PLACED HERE"/></p> Where you see "CODE PLACED HERE" is where i need the video id placed and then for it to be displayed. Any idea how I would do this? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/246584-how-to-output-the-html-code-so-it-is-visible-and-can-be-copied-by-user/ Share on other sites More sharing options...
cyberhost Posted September 7, 2011 Author Share Posted September 7, 2011 Sorry found solution echo " <p><p> <img height='350' width='425' class='fw_media_youtube fw-parse' alt='YouTube-$vidid' src='http://thumbs.webs.com/Platform/mediaPreview.jsp?type=YouTube&id=$vidid'/></p> </p>"; Quote Link to comment https://forums.phpfreaks.com/topic/246584-how-to-output-the-html-code-so-it-is-visible-and-can-be-copied-by-user/#findComment-1266270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.