tags:

views:

1011

answers:

2

Hello,

The below is a dump of variable $x (youtube video).

But I want to access media$title, but obviously when I try

$x->media$title->$t

it does not work. Any suggestions on how to access the title of the youtube video?

stdClass Object (

[version] => 1.0 
[encoding] => UTF-8 

[entry] => stdClass Object ( [xmlns] => http://www.w3.org/2005/Atom [xmlns$media] => http://search.yahoo.com/mrss/ [xmlns$gd] => http://schemas.google.com/g/2005 [xmlns$yt] => http://gdata.youtube.com/schemas/2007 [id] => stdClass Object ( [$t] => http://gdata.youtube.com/feeds/api/videos/OQ14NjbEXJM ) [published] => stdClass Object ( [$t] => 2006-10-01T23:21:06.000Z ) [updated] => stdClass Object ( [$t] => 2009-08-25T07:34:28.000Z ) [category] => Array ( [0] => stdClass Object ( [scheme] => http://schemas.google.com/g/2005#kind [term] => http://gdata.youtube.com/schemas/2007#video ) [1] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/categories.cat [term] => Howto [label] => Howto & Style ) [2] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => tutorial ) [3] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => php ) [4] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => sql ) [5] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => mysql ) [6] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => phpmyadmin ) [7] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => lgo666 ) [8] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => computers ) [9] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => video ) [10] => stdClass Object ( [scheme] => http://gdata.youtube.com/schemas/2007/keywords.cat [term] => sexy ) ) [title] => stdClass Object ( [$t] => PHP Tutorial // User Registration w/ SQL [type] => text ) [content] => stdClass Object ( [$t] => PLEASE CHECK OUT THE SECOND VIDEO OF THIS A quick and easy user registration using php, sql and phpmyadmin. For full size and source codes: http://www.neoblob.com/phpsquad/tuts/php/1/ SQL: CREATE TABLE `user` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(20) NOT NULL default '', `password` varchar(50) NOT NULL default '', `email` varchar(40) NOT NULL default '', `ip` varchar(20) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; [type] => text ) [link] => Array ( [0] => stdClass Object ( [rel] => alternate [type] => text/html [href] => http://www.youtube.com/watch?v=OQ14NjbEXJM ) [1] => stdClass Object ( [rel] => http://gdata.youtube.com/schemas/2007#video.responses [type] => application/atom+xml [href] => http://gdata.youtube.com/feeds/api/videos/OQ14NjbEXJM/responses ) [2] => stdClass Object ( [rel] => http://gdata.youtube.com/schemas/2007#video.related [type] => application/atom+xml [href] => http://gdata.youtube.com/feeds/api/videos/OQ14NjbEXJM/related ) [3] => stdClass Object ( [rel] => http://gdata.youtube.com/schemas/2007#mobile [type] => text/html [href] => http://m.youtube.com/details?v=OQ14NjbEXJM ) [4] => stdClass Object ( [rel] => self [type] => application/atom+xml [href] => http://gdata.youtube.com/feeds/api/videos/OQ14NjbEXJM ) ) [author] => Array ( [0] => stdClass Object ( [name] => stdClass Object ( [$t] => lifeg0eson666 ) [uri] => stdClass Object ( [$t] => http://gdata.youtube.com/feeds/api/users/lifeg0eson666 ) ) ) [gd$comments] => stdClass Object ( [gd$feedLink] => stdClass Object ( [href] => http://gdata.youtube.com/feeds/api/videos/OQ14NjbEXJM/comments [countHint] => 365 ) ) [media$group] => stdClass Object ( [media$category] => Array ( [0] => stdClass Object ( [$t] => Howto [label] => Howto & Style [scheme] => http://gdata.youtube.com/schemas/2007/categories.cat ) ) [media$content] => Array ( [0] => stdClass Object ( [url] => http://www.youtube.com/v/OQ14NjbEXJM&f=videos&app=youtube_gdata [type] => application/x-shockwave-flash [medium] => video [isDefault] => true [expression] => full [duration] => 980 [yt$format] => 5 ) [1] => stdClass Object ( [url] => rtsp://rtsp2.youtube.com/CiILENy73wIaGQmTXMQ2NngNORMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp [type] => video/3gpp [medium] => video [expression] => full [duration] => 980 [yt$format] => 1 ) [2] => stdClass Object ( [url] => rtsp://rtsp2.youtube.com/CiILENy73wIaGQmTXMQ2NngNORMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp [type] => video/3gpp [medium] => video [expression] => full [duration] => 980 [yt$format] => 6 ) ) [media$description] => stdClass Object ( [$t] => PLEASE CHECK OUT THE SECOND VIDEO OF THIS A quick and easy user registration using php, sql and phpmyadmin. For full size and source codes: http://www.neoblob.com/phpsquad/tuts/php/1/ SQL: CREATE TABLE `user` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(20) NOT NULL default '', `password` varchar(50) NOT NULL default '', `email` varchar(40) NOT NULL default '', `ip` varchar(20) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; [type] => plain ) [media$keywords] => stdClass Object ( [$t] => tutorial, php, sql, mysql, phpmyadmin, lgo666, computers, video, sexy ) [media$player] => Array ( [0] => stdClass Object ( [url] => http://www.youtube.com/watch?v=OQ14NjbEXJM ) ) [media$thumbnail] => Array ( [0] => stdClass Object ( [url] => http://i.ytimg.com/vi/OQ14NjbEXJM/2.jpg [height] => 90 [width] => 120 [time] => 00:08:10 ) [1] => stdClass Object ( [url] => http://i.ytimg.com/vi/OQ14NjbEXJM/1.jpg [height] => 90 [width] => 120 [time] => 00:04:05 ) [2] => stdClass Object ( [url] => http://i.ytimg.com/vi/OQ14NjbEXJM/3.jpg [height] => 90 [width] => 120 [time] => 00:12:15 ) [3] => stdClass Object ( [url] => http://i.ytimg.com/vi/OQ14NjbEXJM/0.jpg [height] => 240 [width] => 320 [time] => 00:08:10 ) ) [media$title] => stdClass Object ( [$t] => PHP Tutorial // User Registration w/ SQL [type] => plain ) [yt$duration] => stdClass Object ( [seconds] => 980 ) ) [gd$rating] => stdClass Object ( [average] => 3.8587787 [max] => 5 [min] => 1 [numRaters] => 262 [rel] => http://schemas.google.com/g/2005#overall ) [yt$statistics] => stdClass Object ( [favoriteCount] => 549 [viewCount] => 144308 ) ) )
+5  A: 

Try

$x->{'media$title'}->{'$t'}

If you need to access a member in a PHP object that uses illegal characters (namely the $ sign, but also spaces, etc.), you can do the $obj->{'member name'} trick to access it.

dcousineau
thanks a ton.... i dint know that :)
Alec Smart
I'm not pretty sure but, should not be with double quote? $x->{"media$title"}->{"$t"}
inakiabt
@inakiabt: Double quotes will cause php to try and replace `"$title"` with the contents of `$title`, which in his case will probably be null. Using the single quotes prevents you from having to escape the `$` and tells PHP to interpret the string literally, not do variable substitution.
dcousineau
OK. I understand now his problem, I didn't see the entire array. I thought he needed to access to a "mediaSOMESTRING" variable, thanks.
inakiabt
A: 

Thank you!!!!!!

Dheepak