Jump to content

How to output the html code so it is visible and can be copied by user?


cyberhost

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.