Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6637619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:20:12+00:00 2026-05-25T23:20:12+00:00

This is my first question on this site. I’m new to php but i’ve

  • 0

This is my first question on this site. I’m new to php but i’ve followed advice and gotten my hands as filthy with it as possible. Unfortunately now I’m a little stumped with this simple Youtube app i’m trying to create.

I know there are a several related questions out there, but i haven’t yet found a comprehensive solution to my problem.

Anyway, what I’m trying to do is get the urls of videos in a youtube channel, extract the video ID and create an array that i can then pass off to a javascript function for some cool client-side stuff.

Here is my code so far. I’m pretty sure that my issue relates to arrays vs strings and variables in and out of methods. In any case, my array_map function is not working and the showFullFeed() function is only returning one value instead of the array of links.

Any help is much appreaciated. Cheers

 

class ChannelFeed {

function __construct($username) { $this->username=$username; $this->feedUrl=$url='http://gdata.youtube.com/feeds/api/users/'.$username.'/favorites'; $this->feed=simplexml_load_file($url); }

public function getYTid() {

$ytURL = $this->feed->entry->link['href'];

$ytvIDlen = 11; // This is the length of YouTube's video IDs

// The ID string starts after "v=", which is usually right after // "youtube.com/watch?" in the URL $idStarts = strpos($ytURL, "?v=");

// In case the "v=" is NOT right after the "?" (not likely, but I like to keep my // bases covered), it will be after an "&": if($idStarts === FALSE) $idStarts = strpos($ytURL, "&v="); // If still FALSE, URL doesn't have a vid ID if($idStarts === FALSE) die("YouTube video ID not found. Please double-check your URL.");

// Offset the start location to match the beginning of the ID string $idStarts +=3;

// Get the ID string and return it $ytvID = substr($ytURL, $idStarts, $ytvIDlen);
return $ytvID;
} public function showFullFeed() { foreach($this->feed->entry as $video){ return $vidarray[] = $video->link['href']; } } }; $youtube = new ChannelFeed('username'); $vids = $youtube->showFullFeed(); $vidIDs = array_map(getYTid(),$vids);

?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:20:13+00:00Added an answer on May 25, 2026 at 11:20 pm

    This works. Not I changed the stream from favorites to videos that have been uploaded by the channel, so you may want to change that back.

    First, the code for the youtube functions, I put this in a separate php file and imported it, just to keep things tidier.

    <?php
      class ChannelFeed
      {
        function __construct( $username )
        {
            $this->username=$username;
            $this->feedUrl=$url='http://gdata.youtube.com/feeds/api/users/'.$username.'/uploads';
            $this->feed=simplexml_load_file($url);
        }
    
        public function showFullFeed()
        { 
            $vidarray = array();
    
            foreach($this->feed->entry as $video)
            {
                $vidURL = (string)$video->link['href'];
                $vidarray[] = $vidURL;
            }
    
            return $vidarray;
    }
    }
    
    function getYouTubeID($vidURL)
    {
        $ytvIDlen = 11; // This is the length of YouTube's video IDs
    
        // The ID string starts after "v=", which is usually right after 
        // "youtube.com/watch?" in the URL
        $idStarts = strpos($vidURL, "?v=");
    
        // In case the "v=" is NOT right after the "?" (not likely, but I like to keep my 
        // bases covered), it will be after an "&":
        if($idStarts === FALSE)
            $idStarts = strpos($vidURL, "&v=");
    
        // If still FALSE, URL doesn't have a vid ID
        if($idStarts === FALSE)
            die("YouTube video ID not found. Please double-check your URL.");
    
        // Offset the start location to match the beginning of the ID string
        $idStarts +=3;
    
        // Get the ID string and return it
        $ytvID = substr($vidURL, $idStarts, $ytvIDlen);    
    
        return $ytvID;   
    }
    ?>
    

    Next is the code in the main file that calls it

    require_once('youtube_channelfeed.php');
    
    $youtube = new ChannelFeed('username');
    $vids = $youtube->showFullFeed();
    $vidIDs = array_map("getYouTubeID",$vids);
    

    This gets the IDs and stores them in an array using the array map function.

    Thanks for posting the code, I was looking for something to do what this does, so it’s helped me out a lot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question, but i use this site a lot this last
This is my first question. Thanks to everyone who contributes to this site, it's
this is my first question.. so, here we go. i have a site, 100%
This is my first question :). Im writing a little twitter app in PHP
this is the first question I post in this site, so you have to
This is my first question on the site even though i have been coming
it's my first question here, glad to have found this site. My question deals
This is my first question on this site, and I only have a basic
My first question here so let's be brief. I am parsing this site: http://78.133.214.226/fotoweb/Grid.fwx
Preamble So, this question has already been answered, but as it was my first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.