Reputation:
I am a new learner to php. I am trying to retrieve embeded information from youtube videos URLs. I was originally following the code from this SITE but unfortunately the author doesn't provide access to actual code.
I am having difficulties extracting the php variable values so that i can get the embedded video code.
The htmlentities echo is returning this errorsyntax error, unexpected T_CONSTANT_ENCAPSED_STRING
source: SITE
<html>
<form method="post" action="">
URL:
<input type="text" value="<?php $vari ?>" name="yurl"> <!--$vari-->
<br>
<br>
Height:
<input type="text" value="<?php $hth ?>" name="yheight"> <!--$hth-->
<br>
<br>
Width:
<input type="text" value="<?php $wdth ?>" name="ywidth"> <!--$wdth-->
<br>
<br>
Autoplay:
<input type="checkbox" value="<?php $auto1; $auto2; ?>" name="yautop"> <!--$auto1 $auto2-->
<br>
<br>
<input type="submit" value="Generate Embed Code" name="ysubmit">
</form>
</html>
php code for getting youtube url info
<?php
$vari ='';
$step1 =explode ('v=', $vari);
$step2 =explode ('&',$step1[1]);
$auto1='?autoplay=1';
$auto2='&autoplay=1';
//Iframe code with autoplay
echo htmlentities ('<iframe src="http://www.youtube.com/embed/'.$step2[0].$auto1'"
frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>';
//embed code with autoplay
echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'"
type="application/x-shockwave-flash" src="http://www.youtube.com/v/'.$step2[0].$auto2'"
wmode="transparent" embed="" /></embed>');
?>
Upvotes: 0
Views: 598
Reputation: 1271
you can use the below function to get the embed url code from both facebook and youtube the $link is the address shown on the web browser as it is
//get youtube link
function youtube_embed_link($link){
$new=str_replace('https://www.youtube.com/watch?v=','', $link);
$link='https://www.youtube.com/embed/'.$new;
return $link;
}
//get facebook link
function fb_embed_link($link) {
$link = 'https://www.facebook.com/plugins/video.php?href='.$link.'&show_text=0&width=560';
return $link;
}
//get embed url for fb nd youtube
function get_vid_embed_url($link){
$embed_url='sss';
//if video link is facebook
if (strpos($link, 'facebook') !== false) {
$embed_url=fb_embed_link($link);
}
//if video link is youtube
if (strpos($link, 'youtube.com') !== false) {
$embed_url=youtube_embed_link($link);
}
return $embed_url;
}
Upvotes: 0
Reputation: 1815
Try Below Code... Should Work
<?php
$vari ='';
if($_POST)
{
$vari = $_POST['yurl'];
$hth = $_POST['yheight'];
$wdth = $_POST['ywidth'];
$is_auto = 0;
$step1 =explode ('v=', $vari);
$step2 =explode ('&',$step1[1]);
if(isset($_POST['yautop'] ))
{
if($_POST['yautop'] == 1)
$is_auto = 1;
}
$auto1 = '?autoplay='.$is_auto;
$auto2 = '&autoplay='.$is_auto;
//Iframe code with autoplay
echo htmlentities ('<iframe src="http://ww.youtube.com/embed/'.$step2[0].$auto1.'" frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>');
//embed code with autoplay
echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'" type="application/x-shockwave-flash" src="http://www.youtube.com/v/'.$step2[0].$auto2.'" wmode="transparent" embed="" /></embed>');
}
?>
Problems were
Updates
please replace iframe line with below one (note : one "w" was missing in URL it was "ww")
echo htmlentities ('<iframe src="http://www.youtube.com/embed/'.$step2[0].$auto1.'" frameborder="0" width="'.$wdth.'" height="'.$hth.'"></iframe>');
Upvotes: 0
Reputation: 46728
You have missed a concatenation operator (.)
after $step2[0].$auto2
and $step2[0].$auto1
in both the echo blocks.
echo htmlentities (...)
It should be:
echo htmlentities ('<embed width="'.$wdth.'" height="'.$hth.'"type="application/x-shockwave-flash" src="http://www.youtube.com/v/"'.$step2[0].$auto2.'"wmode="transparent" embed="" /></embed>');
Also, in your Iframe code with autoplay
you have misspelled $auto1
. That wouldn't generate an error, but it wont work right.
Upvotes: 1