320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

Hey guys, i’m trying to put together a script that will display a YouTube user’s uploaded videos. I have the script working, but what I need it to do now is generate an xml based off what the php spits out.

The php script below shows the uploaded videos.

PHP code: http://pastebin.com/HWBNyyTz

Here is the XML structure

<playlist title=" ">
            <item title="" id=""/>
</playlist>

So…. i’m trying to get the YouTube ID of the videos inside the “id” attribute value and of course get the YouTube title inside the “title” attribute value.

and also, of course the more video’s the user have uploaded the more the xml would be, For example- if they have 10 videos uploaded it would show like this:

<playlist title=" ">
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
    <item title="" id=""/>
</playlist>

Any help would be greatly appreciated, Thanks.

Timothy

173 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
  • United Kingdom
kungfu-themes says

Google php -> simpleXml, if you’re still having troubles I can help.

320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

Hey, thanks for the speedy reply.

I always try to keep it simple by using SimpleXML. I just can’t figure out attributes with SimpleXML for some reason. Trial and error! Thats how I roll! haha

I’ll get it one way or another, if any other feedback you can provide me, that would be awesome :)

Thanks again, Timothy

173 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
  • United Kingdom
kungfu-themes says

I’ll let you have a go before I post a solution. I think that way it’s better learning :)

But you wanna check out:

http://www.w3schools.com/php/func_simplexml_addattribute.asp
320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

I agree haha Thanks buddy.

173 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
  • United Kingdom
kungfu-themes says

I have to go out for the day, but just in case you come back with questions. I’ve created an example. Should be fairly easy to understand and use.


$xmlstring = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
     <playlist>

     </playlist>
</root>
XML;

$xml = new SimpleXMLElement($xmlstring);

//Add the main title
$xml->playlist[0]->addAttribute("title", "KungFu-themes");

for ( $i = 0; $i < 10; $i++ )
{
     //This is just an example, you would be setting these
     //values dynamically from a file or an array.
     $xml->playlist[0]->addChild("item");
     $xml->playlist[0]->item[$i]->addAttribute("title", "Some Title");
     $xml->playlist[0]->item[$i]->addAttribute("id", "400293882773");
}

/**
 *  @Description: Print out the xmlstring, use htmlentities() for 
 *                  debugging purposes. Remove on actual release.
 *
 */

echo('<pre>');
echo htmlentities($xml->asXML(), ENT_QUOTES);
echo('</pre>');

/** Expected output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
     <playlist title="KungFu-themes"> 
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
         <item title="Some Title" id="400293882773"/>
     </playlist>
</root>

*/
320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

haha I pretty much got it like 30 mins before you posted that, but I will save your code snippet for further coding.

Thanks for your help!

Tim

320 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
  • United States
timmylogue says

OK… i thought I had it working, but I don’t . This is giving me a headache. How much would you charged to knock this out for me?

Anyone else…

173 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
  • United Kingdom
kungfu-themes says

Charge? I do it for free. Just post your code here and your issues you are having, unless you are talking about a mammoth project.

173 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 100 and 1 000 dollars
  • United Kingdom
kungfu-themes says

Also, I’m not sure how complicated you want your script. Or if you are having trouble parsing the youtube xml rather than creating it.

But a simple one I found is on stackoverflow.

http://stackoverflow.com/questions/6617567/how-to-get-the-id-of-the-latest-uploaded-video-in-a-youtube-channel

You could then just loop through to get all the latest videos.

For example item1, item2 etc.

With a little modification you could easily get the title as well.

by
by
by
by
by
by