321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
kungfu-themes says

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

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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
321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

I agree haha Thanks buddy.

173 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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>

*/
321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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.

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by