misse Posted February 22, 2009 Share Posted February 22, 2009 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?? Link to comment Share on other sites More sharing options...
zachary Posted February 22, 2009 Share Posted February 22, 2009 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... Link to comment Share on other sites More sharing options...
misse Posted February 22, 2009 Author Share Posted February 22, 2009 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 Link to comment Share on other sites More sharing options...
zachary Posted February 22, 2009 Share Posted February 22, 2009 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>';?> Link to comment Share on other sites More sharing options...
misse Posted February 23, 2009 Author Share Posted February 23, 2009 thanks a lot brother, u really made it so clear to me :)have a nice day Link to comment Share on other sites More sharing options...
zppblood Posted February 23, 2009 Share Posted February 23, 2009 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 \". Link to comment Share on other sites More sharing options...
zachary Posted February 23, 2009 Share Posted February 23, 2009 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 23, 2009 Share Posted February 23, 2009 I did not have the time to add the slashesHuh? 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>';?> Link to comment Share on other sites More sharing options...
zppblood Posted February 23, 2009 Share Posted February 23, 2009 Justsomeguy's first code needs to escape on " inside the string too. Link to comment Share on other sites More sharing options...
zachary Posted February 24, 2009 Share Posted February 24, 2009 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+.. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 24, 2009 Share Posted February 24, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.