Jump to content
Sign in to follow this  
misse

Run Youtube Videos In Topic?

Recommended Posts

prevousley, i asked about how to play video/audio files in a HTML page. does anyone have an idea about the code that allows me to youtube videos too??

Share this post


Link to post
Share on other sites

On youtube for specific there is a option to embed a video, copy the text, it is just html... so paste it where you want it to display...demo.png

Share this post


Link to post
Share on other sites

i want to add this option to 'create topic page ' in a forum, user will have a text field to write the video URL, when the topic is posted, the video on the url must be detected by somewhat HTML code and run !! i hope that my idea became clearer

Share this post


Link to post
Share on other sites

Thank you for your clarification...I am assuming that you want almost a bbcode to post a video..Well lets take a look at a youtube embed code for this video:

:
<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/uoP-adqg7P4&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/uoP-adqg7P4&hl=en&fs=1" typehttp://w3schools.invisionzone.com/index.php?showtopic=23524&st=0&gopid=130028="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object>

We see this referenced twice:

That would be the direct location of the SWF and the video player, so to manipulate it we have to understand the URL.../v/uoP-adqg7P4&hl=en&fs=1Okay the green part is the name of the video, the red part is stuff you do not need to worry about, so the video at
can be referenced at
which means the video's ID is uoP-adqg7P4.So all you need to do is ask for the user's video ID and rebuild the embed code with that video ID number...
<?php$vid = "uoP-adqg7P4";echo '<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/$vid&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$vid&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object>';?>

Share this post


Link to post
Share on other sites

One problem with your code zachary, variable interpolation requires that the string starts with a " not a '. So change both ' that form the string, and change to " and escaping all of the other " backslashes like \".

Share this post


Link to post
Share on other sites
One problem with your code zachary, variable interpolation requires that the string starts with a " not a '. So change both ' that form the string, and change to " and escaping all of the other " backslashes like \".
It is not a problem since that data the variable will be containing isn't a quote, I did not have the time to add the slashes so I just changed it to a single quote, insecure & sloppy, Yes, but I was just giving an example.

Share this post


Link to post
Share on other sites
I did not have the time to add the slashes
Huh? Cause it takes a while? But writing a bad example is better?It is incorrect. You can't do variable replacement in single-quoted strings, only double-quoted. Run your example and you'll see it prints out the string '$vid', not the value of that variable.
<?php$vid = "uoP-adqg7P4";echo "<object width=\"480\" height=\"295\"><param name=\"movie\" value=\"http://www.youtube.com/v/{$vid}&hl=en&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/{$vid}&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"480\" height=\"295\"></embed></object>";?>

or:

<?php$vid = "uoP-adqg7P4";echo '<object width="480" height="295"><param name="movie" value="http://www.youtube.com/v/' . $vid . '&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $vid . '&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed></object>';?>

Share this post


Link to post
Share on other sites

I'm sorry but this is free help, I gave him the principle on how to do it, and he hasn't comeback with that error which means he got the principle from my code, and implemented it in a working fashion :) Also there is no reason to get angry at me since, I don't get that error on PHP 4... So your answer is really only applicable to php 4+..

Share this post


Link to post
Share on other sites

First, I'm not angry with you. Second, string handling did not change between PHP 4 and PHP 5. Run this on PHP 4 and see what happens:

$test = 123;echo 'the variable is $test';

Third, PHP 4 is 8 or 9 years old now, the majority of people don't use it anymore. PHP 5 has several performance and security improvements that are missing in PHP 4, not to mention the extra extensions and functions (e.g. file_get_contents). And PHP 6 is close to being ready. It's probably time to move on from PHP 4.When you were starting out and asking questions, I didn't give you half answers just because I'm not charging you for my time. I gave your questions the same consideration I give other people.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...