views:

62

answers:

3

Hi guys,

I have a very basic query string which passes a ID to a receiving page.

On that page, I need to dynamically call the YouTube API, giving my playlistID.

I'm having to use PHP for this, and it's a little out of my comfort zone, so hopefully someone can wade in with a quick fix for me.

Here is my variable

$playlist;

And I need to replace the 77DC230FBBCE4D58 below with that variable.

$feedURL = 'http://gdata.youtube.com/feeds/api/playlists/77DC230FBBCE4D58?v=2';

Any help, as always, greatly appreciated!

A: 
$feedURL = 'http://gdata.youtube.com/feeds/api/playlists/' . $playlist . '?v=2';

you use a full stop to join strings in PHP

thecoshman
thanks for the answer, was just what I needed. Now to go read a bit deeper on php!
Simon Hume
+2  A: 

Once the $playlist variable is set you can construct the feed URL as :

$feedURL = 'http://gdata.youtube.com/feeds/api/playlists/' . $playlist . '?v=2';

or

$feedURL = "http://gdata.youtube.com/feeds/api/playlists/$playlist?v=2";
codaddict
Worked great, thanks!
Simon Hume
+1  A: 
$feedURL = 'http://gdata.youtube.com/feeds/api/playlists/'.rawurlencode($playlist).'?v=2';

Or perhaps a little neater:

$feedurl = sprintf(
    'http://gdata.youtube.com/feeds/api/playlists/%s?v=2',
    rawurlencode($playlist)
);

(Note: rawurlencode is used just in case [not that it's likely with YouTube playlist IDs] the $playlist value contains any funky characters.)

More infos:

salathe
great, thanks. Will give that try in addition to the tips above
Simon Hume