Jump to content

PHP Simple question


jemsz

Recommended Posts

Gretings all.

Right now i use wordpress and in my post i can add a Video by entering the Youtube address into a Custom field called "video_url" and then it outputs the video on my site wich works easy, here it is:

<div class="video">

      <html><center>  
<?php
$meta_value = get_post_meta($post->ID, 'video_url', true);
if($meta_value){
$url = parse_url($meta_value);
$id = 0;
if($url['host'] == 'youtu.be'){$id = ltrim($url['path'],'/');}
else if(strpos($url['path'],'embed') == 1){$id = end(explode('/',$url['path']));}
else{parse_str($url['query']);$id = $v;}
echo '<p><iframe width="540" height="355" frameborder="1" allowfullscreen="true"  src="http://www.youtube.com/embed/'.$id.
'?version=3&theme=light&fs=1&rel=0&cc_load_policy=1&iv_load_policy=1&modestbranding=1" type="application/x-shockwave-flash" allowScriptAccess="always" allowfullscreen="true" width="600" height="355">
</iframe></p>';
}


?>

</div>

However i am tring to add this Modification here in wich adding the video link custom field will also bring back the youtube video title and descripiton,

<?php
$video_id = ’48J_DIZBNyE’;
$video_info = simplexml_load_file(‘http://gdata.youtube.com/feeds/api/videos/’.$video_id.’?v=1′);
echo $video_info->title . ‘<hr>’; // title
echo $video_info->content; // description
?>

Could anyone please help me implement the bottom code with the top piece of code !!

Mucg respect><

Thanks

Link to comment
https://forums.phpfreaks.com/topic/279630-php-simple-question/
Share on other sites

Does this help you?

 

<div class="video">
 
      <html><center>  
<?php
$meta_value = get_post_meta($post->ID, 'video_url', true);
if($meta_value){
   $url = parse_url($meta_value);
   $id = 0;
   if($url['host'] == 'youtu.be'){
      $id = ltrim($url['path'],'/');
   } else if(strpos($url['path'],'embed') == 1){
      $id = end(explode('/',$url['path']));
   }
} else {
   parse_str($url['query']);
   $id = $v;
}
$video_info = simplexml_load_file(‘http://gdata.youtube.com/feeds/api/videos/’.$id.’?v=1');
 
echo '<h3>'.$video_info->content.'</h3><hr /><p><iframe width="540" height="355" frameborder="1" allowfullscreen="true"  src="http://www.youtube.com/embed/'.$id.
'?version=3&theme=light&fs=1&rel=0&cc_load_policy=1&iv_load_policy=1&modestbranding=1" type="application/x-shockwave-flash" allowScriptAccess="always" allowfullscreen="true" width="600" height="355">
</iframe></p><p>'.$video_info->content;.'</p>';
 
?>
 
</div>
NB: *Not* linted....
Link to comment
https://forums.phpfreaks.com/topic/279630-php-simple-question/#findComment-1438244
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.