I am trying to use the youtube API to pulldown some videos for my site. Currently am running this code here:
//Youtube Videos Pull Down
$youtubeURL = "http://gdata.youtube.com/feeds/api/videos?alt=json&q=cats+cradle+chapel+hill&orderby=published&max-results=10&v=2";
$youtubeSearch = file_get_contents($youtubeURL, true);
$youtubeArray = json_decode($youtubeSearch, true);
Not having any problems accessing certain elements of the associative array however youtube’s api is putting $ in many of its array elements .. such as [media$group]
Anytime I try to access an array with one of the $ elements in it, it doesn’t work. Suggestions?
I have tried preg_replace but can’t seem to get my expression right.
You should be able to access it just fine, you just need to make sure to use single quotes or else php will try to interpolate
$groupas a variable, so:$youtubeArray['media$group']And if you want to use it in
preg_replace, you have to escape it with a backslash:\$.$is a valid regex identifier, so the regex is getting tripped up on it.If you do replace it though, you should use
str_replace. There is no need to bring (slower) regular expressions into this.