What is the best way to embed Youtube videos? [closed]

馋奶兔 提交于 2019-12-20 03:38:07

问题


I'm building a video website and I want my users to be able to upload or embed videos from Youtube. The Youtube API doesn't seem to provide video upload from their website, or do they? So I tried to embed videos via an iframe with PHP. Here is the code:

<?php
$source=$_POST['source'];
?>

<html>
<div id="bo"><?php echo $source;?></div>
<form action="altupload.php" method="post">
<input type="text" name="source">
<input type="submit">
</form>
</html>

But all I get is:

<html><div id="bo"><iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/tZa5hyb0_wA\" frameborder=\"0\" allowfullscreen></iframe></div>`

<html>
<form action="altupload.php" method="post">
<input type="text" name="source">
<input type="submit">
</form>
</html>

Can anyone recommend some other ways to do it? Thanks


回答1:


Allow the user upload only youtube video ID from URL as :

http://www.youtube.com/watch?v=Vw5FDZRGTL0

video ID : Vw5FDZRGTL0

and you can set other options of IFrame tag :

<iframe width="420" height="315" src="http://www.youtube.com/embed/<?php echo $videoID; ?>" frameborder="0" allowfullscreen></iframe>  

Good Luck




回答2:


You need to use the addslashes() function:

echo Addslashes($source);


来源:https://stackoverflow.com/questions/15311120/what-is-the-best-way-to-embed-youtube-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!